button = script.Parent local item = game:GetService("ReplicatedStorage"):WaitForChild("Sword") local plr = script.Parent.Parent.Parent.Parent.Parent local frame = script.Parent.Parent
script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Parent.ItemEquipper.Text = "EquippedTool = Sword" local clone = item:Clone() clone.Parent = plr.Backpack frame.Visible = false plr.Character:MoveTo(game.Workspace.Tp.Position) end)
This works in studio but not in-game. I have defined everything and its in a script so its server sided but Clone() won't work even tho its on a script. To be honest, nothing works after the function.
button = script.Parent local item = game:GetService("ReplicatedStorage"):WaitForChild("Sword") local plr = script.Parent.Parent.Parent.Parent.Parent local frame = script.Parent.Parent script.Parent.MouseButton1Click:Connect(function() script.Parent.Parent.Parent.ItemEquipper.Text = "EquippedTool = Sword" local clone = item:Clone() clone.Parent = plr.Backpack frame.Visible = false plr.Character:MoveTo(game.Workspace.Tp.Position) end)
RemoteEvent
into ReplicatedStorage
. Instead of using MoveTo
to move the character, use SetPrimaryPartCFrame
.-- LocalScript local button = script.Parent local ReplicatedStorage = game:GetService("ReplicatedStorage") local CloneTool = ReplicatedStorage:WaitForChild("CloneTool") local plr = button.Parent button.MouseButton1Click:Connect(function() CloneTool:FireServer("Sword") script.Parent.Parent.Parent.ItemEquipper.Text = "EquippedTool = Sword" end)
-- Server script, in ServerScriptService local ReplicatedStorage = game:GetService("ReplicatedStorage") local CloneTool = ReplicatedStorage:WaitForChild("CloneTool") CloneTool.OnServerEvent:Connect(function(player, toolName) -- placed sword in server storage so it's secure local clone = game:GetService("ServerStorage")[toolName]:Clone() clone.Parent = player.Backpack player.Character:SetPrimaryPartCFrame(workspace.Tp.Position) end)