The first parameter here should reference the “Player”, as the server needs to know who requested this event. Your first parameter is rope, so the server is assuming “rope” is the player.
I also noticed that your parameters don’t seem to be lined up: game.ReplicatedStorage.grapple:FireServer(m, rope,attachment1,attachment2,vector)
You have to line up the parameters correctly. On the client it would be (rope, attachment1, attachment2, vector, m) and on the server it would be (Player, rope, attachment1, attachment2, vector, m). Otherwise the script will mix the parameters up.
It still does not work, and doesnt recognize any of the locals sent to the remote event.
game.ReplicatedStorage.grapple.OnServerEvent:Connect(function(player,m,rope,attachment1,attachment2,vector)
vector.Attachment0 = attachment1
vector.Force = Vector3.new(0,0,-4000)
rope.Attachment0=attachment1
local pos = m.Target.Position
rope.Attachment1=attachment2
rope.Visible=true
rope.Color = BrickColor.new("Really black")
local magnitude = (script.Parent.HumanoidRootPart.Position - pos).magnitude
rope.Length = magnitude
while true do
wait()
rope.Length = rope.Length -1
if rope.Length <= 4 then
rope:Destroy()
vector:Destroy()
end
end
end)
It prints an error saying “attempt to index nil with attachment0”
local m = game.Players.LocalPlayer:GetMouse()
local debounce = false
m.KeyDown:connect(function(k)
if k == "f" then
local player = game.Players.LocalPlayer
if m.Target == nil then warn("target not found.") return end
local attachment1 = Instance.new("Attachment",script.Parent.HumanoidRootPart)
local attachment2 = Instance.new("Attachment",m.Target)
local rope = Instance.new("RopeConstraint",script.Parent.HumanoidRootPart)
local vector = Instance.new("VectorForce",script.Parent.Torso)
game.ReplicatedStorage.grapple:FireServer(player,m,rope,attachment1,attachment2,vector)
end
end)
The player parameter here is messing up the server’s parameters. Only the server should have the player parameter, not the localscript.
The server’s referencing the player because it’s taking a local client’s request and it needs to refer to what client was firing. The localscript doesn’t need to include this when firing to the server.
local m = game.Players.LocalPlayer:GetMouse()
local debounce = false
m.KeyDown:connect(function(k)
if k == "f" then
local player = game.Players.LocalPlayer
if m.Target == nil then warn("target not found.") return end
local attachment1 = Instance.new("Attachment",script.Parent.HumanoidRootPart)
local attachment2 = Instance.new("Attachment",m.Target)
local rope = Instance.new("RopeConstraint",script.Parent.HumanoidRootPart)
local vector = Instance.new("VectorForce",script.Parent.Torso)
game.ReplicatedStorage.grapple:FireServer(m,rope,attachment1,attachment2,vector)
end
end)
Server code
game.ReplicatedStorage.grapple.OnServerEvent:Connect(function(player,m,rope,attachment1,attachment2,vector)
vector.Attachment0 = attachment1
vector.Force = Vector3.new(0,0,-4000)
rope.Attachment0=attachment1
local pos = m.Target.Position
rope.Attachment1=attachment2
rope.Visible=true
rope.Color = BrickColor.new("Really black")
local magnitude = (script.Parent.HumanoidRootPart.Position - pos).magnitude
rope.Length = magnitude
while true do
wait()
rope.Length = rope.Length -1
if rope.Length <= 4 then
rope:Destroy()
vector:Destroy()
break
end
end
end)
This is the old script that only fired on the client.
local m = game.Players.LocalPlayer:GetMouse()
local debounce = false
m.KeyDown:connect(function(k)
if k == "f" then
if m.Target == nil then warn("target not found.") return end
local attachment1 = Instance.new("Attachment",script.Parent.HumanoidRootPart)
local attachment2 = Instance.new("Attachment",m.Target)
local rope = Instance.new("RopeConstraint",script.Parent.HumanoidRootPart)
local vector = Instance.new("VectorForce",script.Parent.Torso)
vector.Attachment0 = attachment1
vector.Force = Vector3.new(0,0,-4000)
rope.Attachment0=attachment1
local pos = m.Target.Position
rope.Attachment1=attachment2
rope.Visible=true
rope.Color = BrickColor.new("Really black")
local magnitude = (script.Parent.HumanoidRootPart.Position - pos).magnitude
rope.Length = magnitude
while true do
wait()
rope.Length = rope.Length -1
if rope.Length <= 4 then
rope:Destroy()
vector:Destroy()
end
end
end
end)
PS: Im getting “attempt to index nil with attachment0”
You’re making instances on the client. You cannot translate this to the server, it doesn’t read anything made on the client.
local attachment1 = Instance.new("Attachment",script.Parent.HumanoidRootPart)
local attachment2 = Instance.new("Attachment",m.Target)
local rope = Instance.new("RopeConstraint",script.Parent.HumanoidRootPart)
local vector = Instance.new("VectorForce",script.Parent.Torso)
This is on the client, which is why the server sees it as nil. Whenever you make something on the client, the server cannot read it. That’s why the error pops up.
I think what solves this issue is by moving these instances to the server event and have it deal with the instances there.
Although I’m not sure if this is entirely the case since the error is popping up in a weird spot, try doing this anyway.