I don't know what I'm doing here, please help! I would like for when script.Parent.Transparency = 0, the player earns cash every wait(2).
local stats = Instance.new("IntValue") stats.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Name = "Cash" script.Parent.Transparency = 0 while true do wait(2) cash.Value = cash.Value + 25 end
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) -- 'player' can be identified as an argument for LocalPlayer, since this is in a server script. 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 -- better to have the part in the workspace since it is visible to the player 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