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

Why is the tool not cloning into players backpack?

Ok so I have a localscript in a textbutton that checks if a boolvalue thats in the player is true or not, and then if its true it clones a specified tool into the players backpack but it doesn't clone. Heres the script:

script.Parent.MouseButton1Down:Connect(function()
	local player = game.Players.LocalPlayer
	local Sharingan = game.ReplicatedStorage.KG:FindFirstChild("Itachi Mangekyou"):Clone()
	local SharValue = player.KGvalues:FindFirstChild("Sharingan")
	
	SharValue.Changed:Connect(function()
		if SharValue.Value == true then
			Sharingan.Parent = player.Backpack
		end
	end)
end)

1 answer

Here are a few suggestions first:

I would recommend using the Activated event instead of MouseButton1Down. Also, we really only use the FindFirstChild() function to check whether the object exists. If you're sure the object exists, there's really no point in using it.

Here's what I think the problem that's breaking your script is:

You're firing this from a local script, but you're using it to directly clone something into the player. Because of FilteringEnabled, this will not work.

I would suggest firing a RemoteEvent or RemoteFunction using FireServer() or InvokeServer(). So, I would put a remote event into Replicated Storage and replace line 8 with something along the lines of this:

game.ReplicatedStorage.RemoteEvent:FireServer(player)

Then, I'd create an event in a server script like this:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function(plr)
	local Sharingan = game.ReplicatedStorage.KG:FindFirstChild("Itachi Mangekyou"):Clone()
	Sharingan.Parent = plr.Backpack
end)

2 comments

0

Ok thanks

0

It didn't work :(

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