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

Button that gives tool works fine but stops working when I add "Clone()" at the end of the variable?

So I managed to make the button that gives the tool but now I want it to give infinite amount so it doesn't just work once. That's why I added "Clone()" at the end of the tool variable but it doesn't work when I add that.

LocalScript {inside textbutton inside frame inside screengui}:

script.Parent.MouseButton1Click:Connect(function()
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local GiveRemoteMine = ReplicatedStorage:WaitForChild("GiveRemoteMine")
	local tool = game.ReplicatedStorage.Tools.RemoteMine:Clone()
	GiveRemoteMine:FireServer(tool)
end)

ServerScript {inside folder inside workspace}:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GiveRemoteMine = ReplicatedStorage:WaitForChild("GiveRemoteMine")

GiveRemoteMine.OnServerEvent:Connect(function(player, tool)
	tool.Parent = player.Backpack
end)

If you add ":Clone()" at the end of the "local tool" variable inside LocalScript for some reason everything stops working. And when I get rid of the "Clone()" all of a sudden it starts working but it only gives you one of the tool and then the button is just useless. If someone could help me and tell me how to clone it so the button gives you infinite amount of that tool that'd be awesome!

1 answer

✓ Accepted answer

You're like sending the path of the object, and :Clone() is clientsided, so the server cant move it, easy fix clone the tool on ServerSide.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GiveRemoteMine = ReplicatedStorage:WaitForChild("GiveRemoteMine")

GiveRemoteMine.OnServerEvent:Connect(function(player, tool)
local clone = tool:Clone()
clone.Parent = player.Backpack
end)

Clientsided:

script.Parent.MouseButton1Click:Connect(function()
    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local GiveRemoteMine = ReplicatedStorage:WaitForChild("GiveRemoteMine")
    local tool = game.ReplicatedStorage.Tools.RemoteMine
    GiveRemoteMine:FireServer(tool)
end)

2 comments

1

Thanks a lot. I have learnt something new again!

0

No Problem!

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