Hey so i have this spiderman web swinging system for my game but theres a glitch and The glitch occurs when a player is web-swinging. Instead of moving fluidly towards the target point, the player goes in fast, uncontrollable circles, resulting in erratic movement and potentially disrupting gameplay. I wil also show a clip of the glitch
LocalScript
local uis = game:GetService("UserInputService")
local onweb = false
local plr = game:GetService("Players")
local LocalPlayer = plr.LocalPlayer
local mouse = LocalPlayer:GetMouse()
local Workspace = game:GetService("Workspace")
local Camera = Workspace.CurrentCamera
local char = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")
local animator = hum:WaitForChild("Animator")
local tween = game:GetService("TweenService"):Create(Camera, TweenInfo.new(.4), {FieldOfView = 100})
local tween2 = game:GetService("TweenService"):Create(Camera, TweenInfo.new(.6), {FieldOfView = 70})
local maxslingdistance = 150
local maxzipdistance = 300
local maxshootdistance = 100
local webzipkeycode = Enum.KeyCode.E
local webshootkeycode = Enum.KeyCode.Q
mouse.TargetFilter = workspace.Webs
uis.InputBegan:Connect(function(i, g)
if i.UserInputType == Enum.UserInputType.MouseButton1 and not g then
local mpos = mouse.Hit.Position
if (mpos - char.HumanoidRootPart.Position).Magnitude > maxslingdistance then
return
end
if onweb == false then
onweb = true
tween:Play()
if mouse.X > mouse.ViewSizeX / 2 then
game.ReplicatedStorage.Web:FireServer(true, mouse.Target, mpos, "Right")
hum.PlatformStand = true
else
game.ReplicatedStorage.Web:FireServer(true, mouse.Target, mpos, "Left")
hum.PlatformStand = true
end
end
end
end)
uis.InputEnded:Connect(function(i, g)
if i.UserInputType == Enum.UserInputType.MouseButton1 and not g then
if onweb == true then
onweb = false
tween2:Play()
game:GetService("ReplicatedStorage").Web:FireServer(false)
hum.PlatformStand = false
end
end
end)
ServerScript
local statuses = {}
local webslingspeed = 1000 -- Reduced speed
local tweens = game:GetService("TweenService")
local webzipspeed = 2500
local webreachspeed = 0.45
local radius = 3.5
local WebShootTime = 20
local WebShootSpeed = 0.2
local websize = 4
game:GetService("ReplicatedStorage").Web.OnServerEvent:Connect(function(plr, status, target, point, hand)
if status == true then
local char = plr.Character
if char then
local arm = char:FindFirstChild(hand .. "Hand") or char:FindFirstChild(hand .. "UpperArm")
if arm then
local armattachment = Instance.new("Attachment")
armattachment.Parent = char.HumanoidRootPart
armattachment.WorldPosition = char.HumanoidRootPart.Position
local pointattachment = Instance.new("Attachment")
pointattachment.Parent = target
pointattachment.WorldPosition = point
local bodyGyro = Instance.new("BodyGyro")
bodyGyro.Parent = char.HumanoidRootPart
bodyGyro.P = 10000
bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Parent = char.HumanoidRootPart
bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bodyVelocity.Velocity = Vector3.new()
local rope = Instance.new("RopeConstraint")
local length = (arm.Position - point).Magnitude
rope.Visible = false
rope.Attachment0 = armattachment
rope.Attachment1 = pointattachment
rope.Parent = arm
rope.Length = length
rope.Color = BrickColor.new("White")
rope.Restitution = 0.5
task.wait()
local fakeattach = Instance.new("Attachment")
fakeattach.Parent = target
fakeattach.WorldPosition = arm.Position
local fakeattach2 = Instance.new("Attachment")
fakeattach2.Parent = arm
fakeattach2.WorldPosition = arm.Position
local beam = Instance.new("Beam")
beam.Texture = "rbxassetid://8599205743"
beam.TextureMode = Enum.TextureMode.Stretch
beam.TextureSpeed = 0
beam.TextureLength = 0.1
beam.Transparency = NumberSequence.new(0)
beam.LightEmission = 1
beam.LightInfluence = 0
beam.FaceCamera = true
beam.Attachment0 = fakeattach2
beam.Attachment1 = fakeattach
beam.Width0 = 3
beam.Width1 = 3
beam.Parent = arm
local animator = char.Humanoid:WaitForChild("Animator")
local spider = animator:LoadAnimation(script:WaitForChild("Spider"))
spawn(function()
statuses[plr] = {armattachment, pointattachment, fakeattach, rope, bodyVelocity, bodyGyro, beam}
local tween = tweens:Create(fakeattach, TweenInfo.new(webreachspeed), {WorldPosition = point})
tween:Play()
tween.Completed:Connect(function()
beam.Attachment1 = pointattachment
end)
while true do
if char.Humanoid then
if statuses[plr] ~= nil then
spider:Play()
bodyGyro.CFrame = CFrame.new(char.HumanoidRootPart.Position, point)
bodyVelocity.Velocity = (point - char.HumanoidRootPart.Position).Unit * webslingspeed
else
spider:Stop()
tween:Cancel()
break
end
else
spider:Stop()
tween:Cancel()
break
end
task.wait()
end
end)
else
warn("Arm not found for the specified hand: " .. hand)
end
end
elseif status == false then
if statuses[plr] ~= nil then
for _, v in pairs(statuses[plr]) do
if v and v.Parent then
v:Destroy()
end
end
statuses[plr] = nil
-- Gradual slowdown to prevent flinging
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Parent = plr.Character.HumanoidRootPart
bodyVelocity.MaxForce = Vector3.new(4000, 4000, 4000) -- Damping force
bodyVelocity.Velocity = Vector3.new(0, 0, 0)
task.wait(0.1) -- Short delay to apply damping
bodyVelocity:Destroy()
end
end
end)