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

My Zone Area script isn't functioning properly as i thought? *FIXED*

**Hey, Coders! So Basically my code isn't quite working, here is the code: UPDATE: THE CODE WORKS NOW IT TURNS OUT I HAD TO REARRANGE THE CODE **


game.Players.PlayerAdded:Connect(function(plr)
local door = game.Workspace.Map.Gate
local Sign = door.Sign
local coins = plr:WaitForChild("leaderstats").Honey
local dif = 2000000
local text = script.Parent.SIGN
	coins.Changed:Connect(function(changed)
		print("detected")
	if dif > coinsValue then
		text.Text = "You need "..AddCommas(coins.Value - dif).." More coins to access this area"
			if coins.Value > 2000000 then
				print("unlocked area")
				text.Text = "Area Unlocked"
			door.Door.CanCollide = false
			Sign:Destroy()
			door.Door.BrickColor = BrickColor.new(0, 191, 0)
		end
	end
end)
end)


So the problem is whenever the player hits more than 2,000,000 coins nothing happens even though i scripted what happens next nothing happens here is the code:

			if coins.Value > 2000000 then
				print("unlocked area")
				text.Text = "Area Unlocked"
			door.Door.CanCollide = false
			Sign:Destroy()
			door.Door.BrickColor = BrickColor.new(0, 191, 0)

any help would be awesome!

1 answer

Your code is flawed in many places. First you have written coinsValue instead of coins.Value on line 9. Next you are doing the if statement, inside the first statement. So you are doing. If 2,000,000 is greater than coins.Value and coins.Value is greater than 2,000,000 which will always return false.

This one should work

game.Players.PlayerAdded:Connect(function(plr)
local door = game.Workspace.Map.Gate
local Sign = door.Sign
local coins = plr:WaitForChild("leaderstats").Honey
local dif = 2000000
local text = script.Parent.SIGN
coins.Changed:Connect(function(changed)
    print("detected")
    if dif > coins.Value then
        text.Text = "You need "..AddCommas(coins.Value - dif).." More coins to access this area"
    end
    if coins.Value > 2000000 then
        print("unlocked area")
        text.Text = "Area Unlocked"
        door.Door.CanCollide = false
        Sign:Destroy()
        door.Door.BrickColor = BrickColor.new(0, 191, 0)
    end
end)
end)

1 comment

0

Sorry, didn't see the Update.

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