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

How do I fix Click Tool Remover not working?

Problem: The script does not work once a player clicks on the brick with and without a certain tool in their backpack.

Goal: I want to make is to if a player clicks on a certain part, the script will detect a tool in their backpack. If the certain tool is inside their backpack or if they are holding it, it will be removed and they will earn 5 coins.

TakeToolScript

local find = Character:FindFirstChild("TestTool") or Player.Backpack:FindFirstChild("TestTool")
local coin = game.Players.LocalPlayer.Currency.Coins

function onClick(PersonWhoClicked)
	if find then
		find:Destroy()
		coin.Value = coin.Value + 5
	else
		print("Error finding tools")
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)

Can anyone please help me understand why the script is not working whenever a player clicks the brick. Neither does it print "Error finding tools" nor destroys the TestTool and give Coins.

2 answers

✓ Accepted answer

Your issue with the script is that servers have no access to the local player. What I did below was access the local player via the clicker. Make sure this is all in a Script inside the part

function onClick(PersonWhoClicked)
    local find = PersonWhoClicked.Backpack:FindFirstChild("TestTool")
	local coin = PersonWhoClicked.Currency.Coins
	if find then
        find:Destroy()
        coin.Value = coin.Value + 5
		return
	end
	find = PersonWhoClicked.Character:FindFirstChild("TestTool")
	if find then
		find:Destroy()
	end
end

script.Parent.ClickDetector.MouseClick:Connect(onClick)

I think your script doesn't work because you say "If find then" but find what? Do you understand?

1 comment

0

No he is correctly using "if find then"

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