Quick fix needed for coin collection (Fixed)

  1. What do you want to achieve? Keep it simple and clear!
    Remove the error message for coin collecting
  2. What is the issue? Include screenshots / videos if possible!
    The coins work fine. Just want the error messages to go.
    output for help
    A bool value for the debounce is inside the coin.
	if hit.Name == "Coin" then
		local db = hit.collect
		if db.Value == true then
			db.Value = false
			hit.Transparency = 1
			script.Sound:Play()
			hit:Remove()

You need to check if collect is a valid child under of hit.

hit:FindFirstChild(“collect”) and hit.collect.Value

3 Likes

Is this what you meant? If not, i’m sorry for being a banana.

	if hit.Name == "Coin" then
		local db = hit:FindFirstChild("collect")
		if hit.collect.Value == true then
			hit.collect.Value = false
			hit.Transparency = 1
			script.Sound:Play()
			hit:Remove()

Same error.

Easy fix: use pcall.

Easier fix:

	if hit.Name == "Coin" then
		local db = hit:FindFirstChild("collect") -- Instead of being an error, it will equal `nil` if there is now collect thing.
		if db and db.Value == true then -- Before it checks if the value is true, it checks if it exists at all.
			db.Value = false
			hit.Transparency = 1
			script.Sound:Play()
			hit:Remove()
2 Likes

It was a last resort, guess i’ll just do it. Thanks

1 Like

Also fixed by adding a wait(1) before hit:Remove()

1 Like