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

Coin script isn't working?

I don't know what's wrong with this script. I see nothing wrong with it(perhaps i must've missed something), and there's no errors.

Basically, when you touch the coin, the script checks for your humanoid, if so it creates a variable to the player then adds 1 to the CoinsValue inside a gui in the player's PlayerGui. Then it turns all the decals inside the part, and the part's transparency to 1. It then turns the debounce on so it doesn't repeat for 20 seconds. AND then after 20 seconds, it becomes visible and the debounce turns off.

script:

while true do
	wait()
	script.Parent.Rotation = script.Parent.Rotation + Vector3.new(0, 0, 2)
end

debounce = true

script.Parent.Touched:connect(function(hit)
	print("touched")
	if hit.Parent.Humanoid ~= nil and debounce == true then
		print("humanoid found")
		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		plr.PlayerGui.Coins.TextLabel.CoinsValue.Value = plr.PlayerGui.Coins.TextLabel.CoinsValue.Value + 1
		script.Parent.Transparency = 1
		print("destroying coin")
		debounce = false
		for i,v in pairs(script.Parent:GetChildren()) do
			if v.Name == "Decal" and debounce == false then
				v.Transparency = 1
			end
		end
	end
	print("resetting coin")
	wait(20)
	debounce = true
	script.Parent.Transparency = 0
	for i,v in pairs(script.Parent:GetChildren()) do
		if v.Name == "Decal" and debounce == true then
			v.Transparency = 0
		end
	end
end)

It doesn't print anything in the output either.

1 answer

✓ Accepted answer
game:GetService("RunService").Heartbeat:connect(function() --Same thing as while wait() do.
	script.Parent.CFrame = script.Parent.CFrame*CFrame.Angles(0,0,math.rad(2)) --Use this instead of changing the Rotation Value.
end)

debounce = false

script.Parent.Touched:connect(function(hit)
    print("touched")
    if hit.Parent:FindFirstChild("Humanoid")  and not debounce then --Use findFirstChild when seeing if something exists.
        print("humanoid found") --I didn't  really change anything below :\
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        plr.PlayerGui.Coins.TextLabel.CoinsValue.Value = plr.PlayerGui.Coins.TextLabel.CoinsValue.Value + 1
        script.Parent.Transparency = 1
        print("destroying coin")
        debounce = true
        for i,v in pairs(script.Parent:GetChildren()) do
            if v.Name == "Decal" and debounce then
                v.Transparency = 1
            end
        end
    end
    print("resetting coin")
    wait(20)
    debounce = false
    script.Parent.Transparency = 0
    for i,v in pairs(script.Parent:GetChildren()) do
        if v.Name == "Decal" and debounce == true then
            v.Transparency = 0
        end
    end
end)

Hope it helps!(There was barely anything to change...)

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