also, how do I make it so it works for 1 player only
local ting = 0 --debouncer function onTouched(hit) if ting == 0 then --debounce check ting = 1 --activate debounce check = hit.Parent:FindFirstChild("Humanoid") --Find the human that touched the button if check ~= nil then --If a human is found, then local user = game.Players:GetPlayerFromCharacter(hit.Parent) --get player from touching human local stats = user:findFirstChild("leaderstats") --Find moneyholder if stats ~= nil then --If moneyholder exists then local Coins = stats:findFirstChild("Coins") --Get money Coins.Value = Coins.Value +5 --increase amount of money by the number displayed here (500) wait(20) --wait-time before button works again end end ting = 0 --remove debounce end end script.Parent.Touched:connect(onTouched)
I don't exactly understand what you mean by one player, but as for not working till they reset their character that's rather easy. Each time someone dies, the whole model of their character is destroyed and they respawn. We can use this to our advantage. When the script is activated, put some kind of tag onto them, for example, it can just be a simple BoolValue instance, then name it something like "MoneyBrick". Then in the script, if it detects the name of this instance in the player than don't give them any money.
Okay, so almost an hour of trying to get this to work, I've managed to successfully do it (Could've taken less time but It's currently 4am and I'm super tired). So I previous made the answer without the Timer that you wanted, and I've been working on the Timer. And I finally got it to work. Here's everything you'll need.
You will need a:
Script(x2) Both Their Parent's will be in the part.
A Timer(NumberValue) Which will be stored in the part also. Name it TimeUntilAvailable (Keep it's Value to 0)
A Bool Value (Which will become true if the part is touched.) Name it isTouched.
Another BoolValue (Which will become true if the player has reset, and will be false if they have not reset.) Name it CharacterHasReset
And finally, another Script which will create the CharacterHasReset Value inside of the Character. (Script's Parent will be StarterCharacterScripts)
So here are all the scripts:
Script 1, Timer Script:
local TimeUntilAvailable = script.Parent.TimeUntilAvailable while true do wait(1) if script.Parent.isTouched.Value == true then TimeUntilAvailable.Value = TimeUntilAvailable.Value + 1 if TimeUntilAvailable.Value >= 20 then TimeUntilAvailable.Value = 20 end else TimeUntilAvailable.Value = 0 end end
Script 2, Detecting if the Character touched the Part:
local function onTouched(hit) if hit.Parent:FindFirstChild("Humanoid") ~= nil then local Touched = script.Parent.isTouched local Character = hit.Parent local CharacterHasReset = Character.CharacterHasReset local TimeUntilAvailable = script.Parent.TimeUntilAvailable local Player = game.Players:GetPlayerFromCharacter(Character) local Stats = Player:FindFirstChild("leaderstats") local Coins = Stats:FindFirstChild("Coins") if Touched.Value == false and TimeUntilAvailable.Value == 20 and CharacterHasReset.Value == true then Coins.Value = Coins.Value + 5 CharacterHasReset.Value = false Touched.Value = true TimeUntilAvailable:GetPropertyChangedSignal("Value"):Connect(function() if TimeUntilAvailable.Value == 20 then Touched.Value = false end end) end Player.CharacterAdded:Connect(function() CharacterHasReset.Value = true end) end end script.Parent.Touched:Connect(onTouched)
Script 3, Creating the CharacterHasReset Value. (Insert Script into StarterCharacterScripts)
local CharacterHasReset = Instance.new("BoolValue", script.Parent) CharacterHasReset.Value = true CharacterHasReset.Name = "CharacterHasReset"
Also there may be a simpler way of doing this but I over complicate things when I'm tired. Anyway, Hopefully it all works for you. It should as I just tested and it worked perfectly for me, but if it didn't work for some reason, post a comment and I'll try and help you fix it.
Basically what this will do is it will check if the Parts touchable by checking the Bool Value we added to the Part (isTouched) and it also check if the Timer is equal to 0. If the Timer is equal to 0 and the part is equal to false, using false because we first need to check if it's the value is equal to false then set it to true right after so it wont run again. And we're also checking if the CharacterHasReset is equal to true, if it's equal to true then that means the Character has reset, then they can collect the Coins, if it's not equal to true and it's equal to false then they cannot collect the coins 'til their Character gets respawned, which they'll need to die for that to happen.