Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a script check values before preforming an action?

Asked by 6 years ago
amount = script.Parent.MoneyValue.Value
wait_time = 10   -- change this to how long you want to wait
x = script.Parent
enabled = true

function touch(hit)
if not enabled then return end
enabled = false
local h = hit.Parent:findFirstChild("Humanoid")

if h ~= nil then
local p = game.Players:getPlayerFromCharacter(hit.Parent)
local money = p.leaderstats.Money

if p.TeamColor ~= BrickColor.new("Bright green") then 
if money < 1000 then 
    end
elseif money >= 1000 then
money.Value = money.Value + amount
script.Parent.MoneyValue.Value = 0
p.TeamColor = BrickColor.new("Bright green")
x.Parent.Name = "Finished!"
wait(wait_time)
x.Parent.Name = "Complete Training: 1000"
enabled = true
end
end
end

x.Touched:connect(touch)

I'm trying to make my script check for value before allowing players to switch teams. (Lines 15-18) Im making a brick change teams ontouch if the player just touches any brick then theyll have negative values for their money leaderstats and i'm trying to avoid players having debt on them. What is my script missing in order to preform a value check and if players pass the value check how can I continue the rest of the script?

0
Please indent your code before doing anything else. getPlayerFromCharacter and connect and findFirstChild are deprecated, use GetPlayerFromCharacter and Connect and FindFirstChild. Also don't use global variables but local ones. User#24403 69 — 6y
0
^ true mudathir2007 157 — 6y
0
You have to put Money.Value < 1000 and everywhere u see Money put .Value to it Synkings 0 — 6y

1 answer

Log in to vote
0
Answered by
PolyyDev 214 Moderation Voter
6 years ago

I'm not going to solve this because I have better things to do but to anyone that is going to try to, here is the indented code:

amount = script.Parent.MoneyValue.Value
wait_time = 10   -- change this to how long you want to wait
x = script.Parent
enabled = true

function touch(hit)
    if not enabled then return end
    enabled = false
    local h = hit.Parent:findFirstChild("Humanoid")

    if h ~= nil then
        local p = game.Players:getPlayerFromCharacter(hit.Parent)
        local money = p.leaderstats.Money

        if p.TeamColor ~= BrickColor.new("Bright green") then 
            if money < 1000 then 
            end
        elseif money >= 1000 then
            money.Value = money.Value + amount
            script.Parent.MoneyValue.Value = 0
            p.TeamColor = BrickColor.new("Bright green")
            x.Parent.Name = "Finished!"
            wait(wait_time)
            x.Parent.Name = "Complete Training: 1000"
            enabled = true
        end
    end
end

x.Touched:connect(touch)
Ad

Answer this question