Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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?

3 comments

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.

0

^ true

0

You have to put Money.Value < 1000 and everywhere u see Money put .Value to it

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.