Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I Need Help With The Current Script I Have Not Working, Could You Please Help Me?

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

3 comments

0

Isn't 1 the transparency for a part?

0

??

0

Do you want them to gain cash when the part is visible or invisible? If visible. .Transparency == 0, if invisible, .Transparency == 1. You may also consider adding a wait() statement outside of your conditional statement.

1 answer

✓ Accepted answer

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)

2 comments

0

Thank you!

0

Your welcome! Good luck with your game.

This discussion is preserved as it was. New answers, comments, and votes are closed.