I’m trying to make a singleplayer game with a custom tool system. I have two scripts, a client script and a server script.
The client script fires a remote event when F is pressed which the server script reads. Here’s the client script:
local plr = game:GetService("Players").LocalPlayer
local uis = game:GetService("UserInputService")
local mse = plr:GetMouse()
uis.InputBegan:Connect(function(i, g)
if not g then
if i.KeyCode == Enum.KeyCode.F then
game.ReplicatedStorage.EquipToolsEvent:FireServer(mse, mse.Target)
end
end
end)
and then the server script receives this and attempts to pick up the object:
local evt = game.ReplicatedStorage:WaitForChild("EquipToolsEvent")
local etp = script.Parent:WaitForChild("EquippedToolPos")
evt.OnServerEvent:Connect(function(plr, mse, tgt)
print(tgt)
if tgt then
if tgt.Parent.Name == "Tools" and etp.Parent.ToolEquipped.Value == false then
local tool = tgt
local weld = Instance.new("WeldConstraint",etp)
etp.Parent.ToolEquipped.Value = true
tool.Parent = etp
tool.CFrame = etp.CFrame
tool.CanCollide = false
weld.Part0 = etp
weld.Part1 = tool
else
if etp.Parent.ToolEquipped.Value == true then
for i,v in pairs(etp:GetChildren()) do
if v:IsA("BasePart") or v:IsA("MeshPart") then
v.Parent = workspace.Tools
v.CanCollide = true
etp:ClearAllChildren()
etp.Parent.ToolEquipped.Value = false
end
end
else
etp:ClearAllChildren()
end
end
end
end)
I’ve tried disabling other scripts and editing several parts of my code and this didn’t help.