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.
6 comments
yeah i wasn't actually understandable but i mean i made it so a player has to wait 20 seconds before beeing able to get money again but if someone gets the money the whole server has to wait 20 seconds to get money again
Is that part of the script working?
ye but i don't know lua so much, i can fix things but can't make a fully working script without tutorials
So are you still having any problems? and if so then what are the problems you're having?
i don't know how to make a boolean
Instance.new("Boolean", character).Name = "MoneyBrick" --This is also used to any other kind of instance, the second argument is the parent, but you can also set the parent with "instance.Parent = parent" where the newly created instance is saved into the variable "instance"