I’m trying to make a spiderman webshooter scripter for my upcoming game, the script is a local script, here’s what inside:
local Plr = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
local AmountOfForce = 2750
local F
local P1
local P2
local MD = 150
local Point = Plr.Character.PrimaryPart
local MouseStatus = false
local Able = false
local AllowedPartName = "SwingPart"
local PlayerMouse = Plr:GetMouse()
local Rope
PlayerMouse.Button1Down:Connect(function()
Able = true
end)
PlayerMouse.Button1Up:Connect(function()
Able = false
end)
while wait() do
if MouseStatus then
if PlayerMouse.Target.Name == AllowedPartName then
Able = true
else
Able = false
end
end
end
if PlayerMouse.Target and Able and Rope == nil and PlayerMouse.Target:IsA("BasePart") and (PlayerMouse.Hit.p - Point.Position).Magnitude < MD and not PlayerMouse.Target.Parent:FindFirstChild("Humanoid") and not PlayerMouse.Target:IsA("Accessory") then
Rope = Instance.new("RopeConstraint", workspace)
Rope.Color = BrickColor.new("White")
Rope.Visible = true
Rope.Thickness = 0.4
P2 = Instance.new("Attachment",PlayerMouse.Target)
P1 = Instance.new("Attachment",Point)
P1.WorldPosition = Vector3.new(Point.Position.X,Point.Position.Y,Point.Position.Z)
P2.WorldPosition = PlayerMouse.Hit.p
local Pos = P2
Rope.Attachment0 = P1
Rope.Attachment1 = P2
Rope.Length = (P1.WorldPosition - P2.WorldPosition).Magnitude + 1.2
if not Point:FindFirstChild("BodyForce") then
F = Instance.new("BodyForce")
F.Force = cam.CFrame.LookVector * Vector3.new(AmountOfForce,0,AmountOfForce)
end
end
if F ~= nil then
if F.Name ~= nil then
F.Force = cam.CFrame.lookVector * Vector3.new(AmountOfForce,0,AmountOfForce)
end
else
if game.Workspace:FindFirstChild("RopeConstraint") then
game.Workspace.RopeConstraint:Destroy()
if Plr.Character.HumanoidRootPart:FindFirstChild("BodyForce") then
Rope:Destroy()
Rope = nil
P1:Destroy()
P2:Destroy()
wait(0.25)
F:Destroy()
end
end
end
There’s no errors in the output, so I assume it’s something complicated that I wasn’t thinking about. Any advice is helpful, thanks.
You dont have to do it on the server and doing on the server would just make the system less smooth and jittery because ropes on the server and the client sometimes act different, I have some experience.
all these people think they know what they’re talking abt, the reason ur script is not working is because of ur while wait() do script, try either wrapping it in a coroutine, or put it at the bottom of ur script, that will fix it, also dont forget to parent ur BodyForce
local Plr = game.Players.LocalPlayer
local P1
local P2
local MD = 1000
local character = Plr.Character
if not character or not character.Parent then
character = Plr.CharacterAdded:wait()
end
local Point = character:FindFirstChild("HumanoidRootPart")
if not Point then
Point = character:WaitForChild("HumanoidRootPart")
end
local PlayerMouse = Plr:GetMouse()
local Rope
PlayerMouse.Button1Down:Connect(function()
if PlayerMouse.Target and (PlayerMouse.Hit.p - Point.Position).Magnitude < MD and not PlayerMouse.Target.Parent:FindFirstChild("Humanoid") and not PlayerMouse.Target:IsA("Accessory") then
Rope = Instance.new("RopeConstraint", workspace)
Rope.Color = BrickColor.new("White")
Rope.Visible = true
Rope.Thickness = 0.4
P2 = Instance.new("Attachment", PlayerMouse.Target)
P1 = Instance.new("Attachment", Point)
P1.WorldPosition = Vector3.new(Point.Position.X,Point.Position.Y,Point.Position.Z)
P2.WorldPosition = PlayerMouse.Hit.p
Rope.Attachment0 = P1
Rope.Attachment1 = P2
Rope.Length = (P1.WorldPosition - P2.WorldPosition).Magnitude + 1.2
while Rope.Length > 5 do
wait()
Rope.Length = Rope.Length - 6
end
end
end)
PlayerMouse.Button1Up:Connect(function()
Rope.Length = 0
if game.Workspace:FindFirstChild("RopeConstraint") then
game.Workspace.RopeConstraint:Destroy()
end
end)
To adjust the speed of the rope/web, increase or decrease the numeric value on this line of code: