Weird Stuff Happening with Events

local Buttons = script.Parent
for i,v in Buttons:GetChildren() do	
	if v:IsA("BasePart") then
		local deb = false
		v.Touched:Connect(function(H)
			if not deb and not v:GetAttribute("Completed") and H:FindFirstAncestorWhichIsA("Model").Humanoid then
				local Char = H:FindFirstAncestorWhichIsA("Model")
				local Player = game.Players:GetPlayerFromCharacter(Char)
				if Player.leaderstats.Money.Value > 500 then
					deb = true
					print(Player.leaderstats.Money.Value)
					wait(2)
					deb = false
				else
					deb = true
					warn("You Require "..tostring(500-Player.leaderstats.Money.Value))
					wait(2)
					deb = false
				end
			end
		end)
	end
end

This is a Script my Friend Gave me to Fix…
i first tried it noticed nothing then realised i didnt set up the leaderstats so i started to set it up. now when the Leaderstats were ready when i stepped on it without any money (0) it was working and warned perfectly…
it was until i used the command bar to give my self 500+ coins like this:

game.Players.IamNewToRiblix.leaderstats.Money.Value += 500

but when i pressed on the pressure plate it was just warning me “You Require 500”…

I Tried to Fix it by Disconnecting the Event,Adding more Debs… but that didnt work.

any help will be appreciated.

1 Like

just found more info, if you touch the part even with the required amount it just prints “You Require 500”

because it needs to be
if Player.leaderstats.Money.Value > 499 then

I See what you are trying to explain but i have like 1000 in that IntValue so this shouldnt happen

Hello! I have fixed your script, sorry it took a while but here is the script!

local Buttons = script.Parent
for i,v in Buttons:GetChildren() do	
	if v:IsA("BasePart") then
		local deb = false
		v.Touched:Connect(function(H)
			if not deb and not v:GetAttribute("Completed") and H:FindFirstAncestorWhichIsA("Model").Humanoid then
				local Char = H:FindFirstAncestorWhichIsA("Model")
				local Player = game.Players:GetPlayerFromCharacter(Char)
				if Player.leaderstats.Money.Value > 500 then
					deb = true
					print("Player has enough")
					wait(2)
					deb = false
				else
					deb = true
					warn("You Require 500")
					wait(2)
					deb = false
				end
			end
		end)
	end
end

Did you use the command on the server?

1 Like

Thank you so much for taking time to write this but unfortunately I can’t tell if it works because im away from my computer right now.

Yes indeed. Every command ran on the command line runs on server.

All commands ran on the command line actually isn’t ran on the server, its ran on the current mode. Are you sure you changed the mode to Server and then ran it?

If you’re talking about something else sorry.

Yep 100 Percent. (Also the script here is a Server Script. Just extra info nothing relevant.)

Oh okay, thanks for clarifying.

perhaps share any errors if they happen so i can understand what breaks the code

yo my code works dawg. dont worry

AYO IT ACTUALLY WORKED.

but just one question. what did you change in the script. it just seems the same.

1 Like

changed the prints… thats all :frowning:

1 Like