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

Clone() and Move() Error? Everything is defined and its in a script so its server-sided

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.

1 comment

1

Please post the code in a code block.

2 answers

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)

###Do not use a server script to handle GUI code. Instead, use a local script. Insert a 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 code:

-- 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)

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