#Easy script but not working, pls

65 messages · Page 1 of 1 (latest)

green forum
#

local button = script.Parent
local debounce = false
local rebirthCost = 50
local rebirthInterval = 0.20
local players = game:GetService("Players")

local function updateButtonColor(player)
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local money = leaderstats:FindFirstChild("Money")
if money then
if money.Value >= rebirthCost then
button.Color = Color3.fromRGB(0, 255, 0)
else
button.Color = Color3.fromRGB(255, 0, 0)
end
end
end
end

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
updateButtonColor(player)

    local leaderstats = player:WaitForChild("leaderstats")
    local money = leaderstats:WaitForChild("Money")
    
    money.Changed:Connect(function()
        updateButtonColor(player)
    end)
end)

end)

button.Touched:Connect(function(hit)
local character = hit.Parent
local player = players:GetPlayerFromCharacter(character)

if player and not debounce then
    local leaderstats = player:FindFirstChild("leaderstats")
    if leaderstats then
        local money = leaderstats:FindFirstChild("Money")
        local rebirths = leaderstats:FindFirstChild("Rebirths")
        local buttonsPressed = leaderstats:FindFirstChild("ButtonsPressed")

        if money and rebirths and buttonsPressed then
            if money.Value >= rebirthCost then
                debounce = true
                money.Value = 0
#

rebirths.Value = rebirths.Value + 1
buttonsPressed.Value = buttonsPressed.Value + 1

                while debounce do
                    wait(rebirthInterval)
                    if money.Value >= rebirthCost then
                        money.Value = 0
                        rebirths.Value = rebirths.Value + 1
                        buttonsPressed.Value = buttonsPressed.Value + 1
                    else
                        debounce = false
                    end
                end
            end
        end
    end
end

end)

#

**I want the part to change collor depending on ammount of Money the player has. But it doesnt work.
**

ocean ember
#

how do u even code like this

#

this is insane

#

look at my post ;-;

green forum
#

most times he is very good but this aint working

green forum
ocean ember
#

try this ai

#

its one coding bacon made

#

just for coding on roblox

#

maybe that will help fix it

#

and this is my post

green forum
green forum
#

that bot is so stupid lol

#

anyone that knows an solution? pls

ocean ember
finite frigate
finite frigate
ocean ember
#

i suck at this then

finite frigate
#

Isn't it AI code?

ocean ember
#

better than what i could do

finite frigate
#

If AI made it than how is it your fault.

ocean ember
#

ever hope to do too

#

whats my fault?

#

i just wanna learn to code tbh

finite frigate
#

Then use anything but AI man.

ocean ember
#

im not using ai

#

im using YT'

finite frigate
#

So AI didnt make it or what

ocean ember
#

@green forum

finite frigate
#

Yk what whatever

#

Let's focus on the problem

ocean ember
#

?

#

bro i didnt understand 90% of what was in that code

finite frigate
#

Or is it one of those floor buttons you step on

ocean ember
#

he should of added some comments to clarify some stuff

#

using these thingys --

finite frigate
#

He's using button.touched so its the second hting

#

.Touched is only for BaseParts

#

3D Objects

ocean ember
#

isnt .touched just to represent when it gets touched

#

by another part

finite frigate
#

That's exactly what that is

patent pineBOT
#

studio** You are now Level 17! **studio

finite frigate
# green forum local button = script.Parent local debounce = false local rebirthCost = 50 local...
local button = script.Parent
local db = false
local rCost = 50
local rInterval = 0.20
local Players = game:GetService("Players")
local char

button.Touched:Connect(function(hit)
    if db then return end
    
    db = true
    
    if hit.Parent:FindFirstChild("Humanoid") then
        char = hit.Parent
    end
    
    local plr = Players:GetPlayerFromCharacter(char)
    local leaderstats = plr:FindFirstChild("leaderstats")
    local money: IntValue = leaderstats:FindFirstChild("Money")
    local rebirths: IntValue = leaderstats:FindFirstChild("Rebirths")
    local btPressed: IntValue = leaderstats:FindFirstChild("ButtonsPressed")
    
    if money.Value >= rCost then
        button.Color = Color3.fromRGB( 0, 255, 0)
        money.Value = 0
        rebirths.Value +=  1
        btPressed.Value += 1
    else
        button.Color = Color3.fromRGB( 255, 0, 0 )
    end
    
    task.wait(rInterval)
    
    db = false
    
end)
ocean ember
#

how in the hell does someone script like this

#

like what

#

debounce?

#

wdym if debounce then return end ;-;

finite frigate
#

It checks if debounce is true and if it is, the thread is stopped and won't continue.

finite frigate
green forum
#

But things like this didn´t

#

Thanks for your help

finite frigate
#

I asked the AI to make a script that makes a brick change colour everytime it gets touched