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

How can I successfully clone a tool from a local script?

I've actually done the code already and this actually works:

Server Script

local debounce = true
local rs = game:GetService("ReplicatedStorage")
local SampleRemoteEvent = rs:FindFirstChild("SampleRemoteEvent")

script.Parent.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		if not debounce then
			return
		end
		debounce = false
		--Firing a remote event to the client so that the local script can clone the tool into the workspace
		
		local player = game.Players:GetPlayerFromCharacter(hit.Parent)
		SampleRemoteEvent:FireClient(player)
		
	end
end)

Local Script

local rs = game:GetService("ReplicatedStorage")
local SampleRemoteEvent = rs:FindFirstChild("SampleRemoteEvent")

local ToolToClone = rs:FindFirstChild("Egg")
SampleRemoteEvent.OnClientEvent:Connect(function()
	ToolToClone:Clone().Parent = game.Workspace
end)

What works: All my code works. Once a player has touched a brick, I want to have a tool spawn on the ground so the player can pick up the tool. This tool should ONLY be seen by this player hence why I need to use the client side of things.

The issue: The tool is not able to be picked up. It isn't accessible by even the client. The good thing is, it can be seen only by the player, but they cant be picked up which is the issue.

If anyone can point me in the right direction or give me an explanation as to why this is the case.

Feel free to test it in studio, ive done many tests. It's most likely a simple concept error on my part.

2 comments

0

I don't think the issue here is with the LocalScript and ServerScript since they have done their job. Their job is: when a player hit the brick, fires RemoteEvent, LocalScript receives it and clone the tool. So I think the problem is with the script of your tool, maybe there's something wrong with the "pick up" script, Im not sure, you can check it

0

There's no pick up script. I literally tried cloning it with the server script and it picked up perfectly. Therefore Im not sure if what im trying to do is even possible

1 answer

You don't have to use a remote event. Just insert a Script into your brick that you want a player to touch. I'm sorry, I haven't really learned how you can make something visible only to certain players. I'd advise you to put your tool into ServerStorage and then it will be cloned into the Workspace by the Script. See if this works:

local debounce = false

script.Parent.Touched:Connect(function(hit) -- Player hits brick and tool gets cloned.
	if hit.Parent:FindFirstChild("Humanoid") then
	if debounce == false then
		debounce = true
		local ToolToClone = game.ServerStorage:FindFirstChild("Egg")
		ClonedTool = ToolToClone:Clone() -- Naming the tool something different, so you don't get the two mixed up.
		ClonedTool.Parent = game.Workspace
		-- Here, you're going to want to type in where you want the ClonedTool to spawn.
		debounce = false
		end
	end
end)

ClonedTool.Touched:Connect(function(hit) -- When player walks over or touches the tool, it will be added to their backpack and equipped.
	local humanoid = hit.Parent:FindFirstChild("Humanoid")
		if humanoid then
		if debounce == false then
			debounce = true
			ClonedTool.Parent = game.Players:GetPlayerFromCharacter(hit.Parent).Backpack
			humanoid:EquipTool(ClonedTool)
			debounce = false
		end
	end
end)

Hope this helps!

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