Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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

Log in to vote
1
Answered by
sayer80 457 Moderation Voter
3 years ago
Edited 3 years ago

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)
1
Thanks a lot. I have learnt something new again! Nitrolux200 62 — 3y
0
No Problem! sayer80 457 — 3y
Ad

Answer this question