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

Trying to make this script respawn a coin but dont know were I went wrong, help?

debounce = false

script.Parent.Touched:Connect(function(hit)

if debounce == false then

debounce = true

	if hit.Parent:FindFirstChild("Humanoid") then

    	local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

			if plr~=nil then

            	if plr:FindFirstChild("Stats") and plr:FindFirstChild("Main") and plr.Main:FindFirstChild("CandysQ3") and  plr.Stats:FindFirstChild("????Candys") and 

plr.Main:FindFirstChild("BoostCandy") then

                	local coins = plr.Stats["????Candys"]

					local CandysQ3 = plr.Main["CandysQ3"]

						if plr:WaitForChild("Main").BoostCandy.Value == 0 then

	                		coins.Value = coins.Value + 1

							CandysQ3.Value = CandysQ3.Value + 1
						else

							coins.Value = coins.Value + 

1+plr:WaitForChild("Main").BoostCandy.Value CandysQ3.Value = CandysQ3.Value + 1

						end
					end
				end
			script.Parent:Destroy()
		end
	debounce = false
end

end)

1 comment

0

Fix the code block.

1 answer

You did not create the coin so you would need to do:

debounce = true

    if hit.Parent:FindFirstChild("Humanoid") then

        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)

            if plr~=nil then

                if plr:FindFirstChild("Stats") and plr:FindFirstChild("Main") and plr.Main:FindFirstChild("CandysQ3") and  plr.Stats:FindFirstChild("????Candys") and 

plr.Main:FindFirstChild("BoostCandy") then

local coins = plr.Stats["????Candys"]

local CandysQ3 = plr.Main["CandysQ3"]

    if plr:WaitForChild("Main").BoostCandy.Value == 0 then

        coins.Value = coins.Value + 1

        CandysQ3.Value = CandysQ3.Value + 1
    else

        coins.Value = coins.Value + 

1+plr:WaitForChild("Main").BoostCandy.Value CandysQ3.Value = CandysQ3.Value + 1

                        end
                    end
                end
	    local coin_clone = script.Parent:Clone()
            coin_clone.CFrame = script.Parent.CFrame
            script.Parent:Destroy()
        end
    debounce = false
end

1 comment

0

would that make it respawn?

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