Why script clone tool to backpack dont work

watch video why dont work? https://youtu.be/LWRleMb5UZ8

Could you also include your code? You copy and paste your code into this format to make it stylized

```
ā€“ code goes here
```
ex:

ā€“ code goes here

From the video, if you want the script to make a copy into the backpack, it seems like the problem is that itā€™s parenting the original copy to the player. There seem to be other bugs too, though with the code we can help with those.

script in prompt

local Prompt = script.Parent

Prompt.Triggered:Connect(function(Player)
local Tool = game.ReplicatedStorage.asd:Clone()
Tool.Parent = Player.Backpack
script.Parent.Parent.Parent:Destroy()
end)

script in tool

local Tool = script.Parent
local playerInputService = game:GetService(ā€œUserInputServiceā€)

local Equipped = false

Tool.Equipped:Connect(function()
Equipped = true
Tool.Handle.ProximityPromp.Enabled = false
end)

Tool.Unequipped:Connect(function()
Equipped = false
end)

playerInputService.InputBegan:Connect(function(input)
if Equipped == true then
if input.KeyCode == Enum.KeyCode.G then
local droppedToolModel = Instance.new(ā€˜Modelā€™)
local clonedHandle = Tool.Handle:Clone()
clonedHandle.CanCollide = true
droppedToolModel.Name = Tool.Name
droppedToolModel.Parent = workspace
clonedHandle.Parent = droppedToolModel
clonedHandle.ProximityPromp.Enabled = true
Tool:Destroy()
end
end
end)

why after dropping the Handle, the script for proximity prompt does not wor

set the position of the droppedToolModel to wherever you want, or it will always spawn in the origin

1 Like

I would check in the explorer if the prompt in the dropped tool has the script in it in a play test. Also make sure to double check outside of a playtest that the template toolā€™s handleā€™s prompt in ReplicatedStorage has the script in it.

Your code looks like it should work to me (though there might be a bug Iā€™m not seeing). Also double check if you get any errors in the output.

Itā€™s a clone of the handle so it gets the same position as the tool handle.

I do not understand why, after dropping it, and i use proximity prompt it is not cloned in the backpack, although everything is correct, I rechecked the script 100 times

rbxl file u can check
dddwfdaf.rbxl (58.6 KB)

1 Like

Itā€™s not replicating to the server for some reason, let me look into this:
Client view:
Screenshot 2024-02-16 at 3.03.20 AM
Server view:
Screenshot 2024-02-16 at 3.03.15 AM

Edit:

Try the code with a server script

Actually, I see, you need the user input. Iā€™ll write you some code really fast to fix that.

So the problem is that you need to drop the tool on the server (scripts run on the server so the proximity prompt script doesnā€™t run if itā€™s dropped on the client), but you need to get the input on the client.

What I did is I created a remote event to convey the G key press to the server through a remote event, then on the server I dropped the tool. I basically split your code in half:
Screenshot 2024-02-16 at 3.09.08 AM

Script (Server script):

local Tool = script.Parent

-- When the server gets the signal from the client, run the drop tool code
script.Parent.DropEvent.OnServerEvent:Connect(function()
	local droppedToolModel = Instance.new('Model')
	local clonedHandle = Tool.Handle:Clone()
	clonedHandle.CanCollide = true
	droppedToolModel.Name = Tool.Name
	droppedToolModel.Parent = workspace
	clonedHandle.Parent = droppedToolModel
	clonedHandle.ProximityPrompt.Enabled = true
	Tool:Destroy()
end)

DropTool (Client script):

local Tool = script.Parent
local playerInputService = game:GetService("UserInputService")

local Equipped = false

Tool.Equipped:Connect(function()
	Equipped = true
	Tool.Handle.ProximityPrompt.Enabled = false
end)

Tool.Unequipped:Connect(function()
    Equipped = false
end)

playerInputService.InputBegan:Connect(function(input)
	if Equipped == true then
		if input.KeyCode == Enum.KeyCode.G then
			-- Send the signal to the server to drop the tool
			script.Parent:WaitForChild("DropEvent"):FireServer()
		end
	end
end)

Hereā€™s a place file:

dddwfdaf.rbxl (58.7 KB)

1 Like

Thanks a lot, everything is working now

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.