Help with a local script

local test = script.Parent.Parent
local Click = script.Parent.Parent.ClickDetector
Click.MouseClick:Connect(function(player)
	test.Parent = game.Workspace[player.Name]
end)

This script is a local script and inside a tool. I have no idea why it isnt working and could anyone help?
(it works in a normal script)

2 Likes

I believe that tools cannot be parented into characters with local scripts. You may want to stick with global scripts. Or you could alternatively use remote events.

1 Like

You wanna set the test part (or wathever it is) inside the players character you basically do this:

local test = script.Parent.Parent
local Click = script.Parent.Parent.ClickDetector
Click.MouseClick:Connect(function(player)
        local Character = player.Character
	test.Parent = Character
end)

it does’nt matter depending on what’s the case

You should use a normal script (server script). I assume your tool is in workspace which can’t run local scripts. Also you can just say player.Character instead of game.Workspace[player.Name].

oh okay. what if i wanted the tool to only seem to be taken by that one person?
(like when someone takes it, if you didnt take it yourself its still there but only on your screen)

You should clone the tool and then give it to the player, for example:

local test = script.Parent.Parent
local Click = script.Parent.Parent.ClickDetector
Click.MouseClick:Connect(function(player)
	Click:Destroy()
	
	local newTest = test:Clone()
	newTest.ClickDetector:Destroy()
	newTest.Parent = player.Character
	
	(the new tests scripts):Destroy()
end)

You should also make sure this script doesn’t run when it’s inside the player, so you should remove the ClickDetector. (and you should also destroy the script so it doesn’t run)
This script should work.

okay thanks.
ill give you solution but going with the code,
can you make it so the item appears invisible after the player touches it, but only for them?

(or did you already do that)

I personally don’t know how to remove it from one player, you can make another topic about it though.

1 Like