✓ Accepted answer
Hello,
You would like to do a script that if the part's transparency is == 0 then you would like the player's cash to go up by 25, from waiting 2 seconds.
First of all, let us look at your original code:
local stats = Instance.new("IntValue")
The first line of the code is incorrect. The reason is because there is no specific place for the IntValue to be parented of, so the leaderstats is not the Players.
Also, the cash instancing is also incorrect for the same reason, it is inserted not into leaderstats.
Since this is a server script, LocalPlayer is not a variable that can be used, since this is dealing for the server, and not locally for the client. In that case, we'd need a function that runs whenever the player has joined the game, so then we are able to create a variable for the local player.
So, the correct code would be:
game.Players.PlayerAdded:Connect(function(player)
local stats = Instance.new("Folder")
stats.Name = 'leaderstats'
stats.Parent = player
local cash = Instance.new("IntValue")
cash.Name = 'cash'
cash.Parent = stats
local part = workspace.Part
while part.Transparency == 0 do
wait(2)
cash.Value = cash.Value + 25
end
end)
--
Thank you,
Creeperthekid32
Social Media if erroring occurs:
Roblox: Creeperthekid32
Twitter: @creeperthekid32
Discord: Creep#7611
3 comments
what
um u didnt even set the parent of the IntValues lol
@EXpodo1234ALT The parent does not have to be set in order to change the property of objects. Now, if he wants to make a leaderboard, then he'd have to put it into the player.