I am wanting to make it so that if you press a key, this will then toggle a serverscript which will move the players arm.
I am not sure what I’ve done wrong, however, nothing I try seems to work. I would just like to know what I’ve done wrong and how I can fix it.
Here is my current script
local Player = script.Parent.Parent
local Char = Player.Character
local UIS = game:GetService("UserInputService")
local debounce = false
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E then
if not debounce then
debounce = true
local Weld = Instance.new("Weld")
Weld.Name = "Tool_Weld1"
Weld.Part0 = Char.Torso
Weld.Part1 = Char['Right Arm']
Weld.Parent = Char.Torso
Weld.C1 = CFrame.new(-1.5, 0.75, -0.5) * CFrame.fromEulerAnglesXYZ(math.rad(180), 0, math.rad(-20))
else
Char.Torso:FindFirstChild("Tool_Weld1"):Destroy()
debounce = false
end
end
end)
You are doing all of this in a local script. What you need to do is have the local script fire a RemoteEvent when the E key is pressed. On the server (in some server script), listen for when the RemoteEvent is fired from the client and then move the arm on the server.
You will need 2 scripts for this, one local and one server script. Here is the documentation for RemoteEvents.
Scripts won’t work in StarterPlayerScripts, only LocalScripts.
Try to use this:
Create 2 RemoteEvent’s in ReplicatedStorage (Name first one “WeldCreator”, and the second one “WeldRemover”), And then Create LocalScript in StarterPlayerScripts with script:
local Player = script.Parent.Parent
local Char = Player.Character
local UIS = game:GetService("UserInputService")
local debounce = false
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.E then
if not debounce then
debounce = true
game:GetService("ReplicatedStorage").WeldCreator:FireServer()
else
game:GetService("ReplicatedStorage").WeldRemover:FireServer()
debounce = false
end
end
end)
And create Script in “ServerScriptService” with this script: