So, for the game that I am working on, I decided to add a cash value to the leaderstats and then make a door that you can walk through if you have enough cash.
I am decently new to programming and was just wondering if anyone had any feedback on this code that would be great, thank you.
game.Players.PlayerAdded:Connect(function(plr)
local stats = Instance.new("BoolValue",plr)
stats.Name = "leaderstats"
local cash = Instance.new("IntValue",stats)
cash.Name = "Cash"
cash.Value = 0
if cash.Value >= 100 then
game.Workspace.Door.CanCollide = true
else
game.Workspace.Door.CanCollide = false
end
end)
Make it so it’ll only check the players value when you interact with the door in some way. I’m assuming you already know how to do this, and I’m not much of a scripter myself.
If you want the door to be entered, don’t do it in a server sided script since it’ll be for everyone meaning one person can have 100 cash and people will be able to enter it even without 100 cash or above.
For simple terms and instead of the player having to rejoin once they get 100 cash…
You should make it so you add a touched function to the door, when it gets touched, you should check if the player who touched it has 100 cash using players:GetPlayerFromCharacter(chr), make sure it’s in a local script so it’s only seen for the player who has the 100 cash, not everyone who doesn’t have 100 cash.
Or you could just make a function if the character respawned and it would make the door be enter-able by the player.
What If an exploiter were to change their value to 100, and just walk through the door? I see a flaw in this, or I’m not understanding this fully.
edit I know local scripts are for the client only, and not to the server. I know exploiters can change their values on the client, but not the server. The server sees 0, but the client sees 100, and they can just bypass that with cheating in the value, and taking advantage of the local script
Try to make a bool value named “CanSet”, if the game tries to give you some value, it should be set to true then it’ll give you it then later set to false, if the player gets value without the game turning the bool value to true, they get kicked or banned if you’d like.