I have a script here, that when the part is transparent == 0, the player is supposed to get +$50 every 5. I'm not sure how to fix the problem, please help!
while true do player = game.Players:GetPlayerFromCharacter if script.Parent.Transparency == 0 then local stats = player:findFirstChild("leaderstats") local add = 50 local cash = stats:findFirstChild("Cash") cash.Value = cash.Value + add wait(5) end end
You were doing GetPlayerFromCharacter but you didnt define from what character
If you are trying to do it from a part being touched do this
local CanGet = true -- If They Can Get Cash From Touch script.Parent.Touched:Connect(function(hit) local HitParent = hit.Parent -- The Parent Of hit if HitParent:FindFirstChild("Humanoid") then -- Checks If The Parent Of The Part That Touched The Part Has A Humanoid. local Player = game.Players:GetPlayerFromCharacter(HitParent) -- Gets The Player From The Players Character if script.Parent.Transparency == 0 and CanGet then -- If The Part Is Visible local stats = player:FindFirstChild("leaderstats") local add = 50 -- Amount To Add local cash = stats:FindFirstChild("Cash") cash.Value = cash.Value + add -- Adds 50("add") to current Cash Amount script.Parent.Transparency = 1 -- Sets part to invisible CanGet = false -- Sets "CanGet" to false wait(5) -- waits 5 seconds script.Parent.Transparency = 0 -- Sets part to visible CanGet = true -- Sets "CanGet" to true end end end)