How would i stop a player from teleporting all over the place when a welded part gets sent to it?

local M1cooldown = true

game.ReplicatedStorage.Attack.OnServerEvent:Connect(function(plr,key)
	if key == "M1" and M1cooldown == true then
		M1cooldown = false
		local hitbox = game.ServerStorage.Hitboxes.SwordSlash:Clone()
		hitbox.Parent = game.Workspace
		hitbox.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.LookVector * 2
		local weld = Instance.new("WeldConstraint")
		weld.Parent = hitbox
		weld.Part0 = plr.Character.HumanoidRootPart
		weld.Part1 = hitbox
		local anim = plr.Character.Humanoid.Animator:LoadAnimation(plr.Character.Humanoid.Animator.Slash)
		anim.Priority = Enum.AnimationPriority.Action
		anim:Play()
		task.wait(0.5)
		weld:Destroy()
		hitbox:Destroy()
		M1cooldown = true
	end
end)

This keeps on happening, tried switching from welds to weldconstraints, same issue, setting C1 and C0 just misalignes the collision, what way can i make it not teleport like that?

1 Like

Client retains network ownership of its character.

Simply put,
the position of your character on your client is what YOU see.
the server is behind, due to replication lag.

  • You call :FireServer() from your client.
  • While that call is replicating, your client position updates.
  • The server receives the event, makes welds the part to where it sees your character.
  • The server tells the client “put the character where I just made this weld”. Basic roblox replication rules
  • Client snaps back to where the server saw it.

Setting the parts network owner to the client before welding may actually solve this.

Otherwise, solution is to create that box on the client then replicate it to other clients if they should see it too.

i’ll be trying that, will reply/solution depending on results

Fixed the teleporting issue by putting the cloning stuff in the client script and replacing serverstorage with replicatedstorage, however now i’ve run into the problem of it completely removing any and all velocity you had, is there a fix for that also?

What do you mean by this? It freezes your character? Could you send a video?


here ye go

can you send how you have your script set up currently?

As well as the properties of “hitbox” that you are cloning.

Make the hitbox cancollide false

its already cancollide to false

Can you send your script, the order of your code matters here.

You should be parenting after you weld.

Since the part is under the same assembly as your character once its welded, collisions will not register by default.

Something else at play potentially. Try making part massless perhaps?

LocalScript

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local CoreEvent = game.ReplicatedStorage.Attack
local M1cooldown = true

UIS.InputBegan:Connect(function(Input, processed)
	if Input.UserInputType == Enum.UserInputType.MouseButton1 then
		M1cooldown = false
		print("M1")
		local plr = game.Players.LocalPlayer
		local hitbox = game.ReplicatedStorage.Hitboxes.SwordSlash:Clone()
		hitbox.Parent = game.Workspace
		hitbox.CFrame = plr.Character.HumanoidRootPart.CFrame + plr.Character.HumanoidRootPart.CFrame.LookVector * 2
		local weld = Instance.new("WeldConstraint")
		weld.Parent = hitbox
		weld.Part0 = plr.Character.HumanoidRootPart
		weld.Part1 = hitbox
		CoreEvent:FireServer("M1")
		task.wait(0.5)
		weld:Destroy()
		hitbox:Destroy()
		M1cooldown = true
	end
end)

ServerScript

local M1cooldown = true

game.ReplicatedStorage.Attack.OnServerEvent:Connect(function(plr,key,arg1)
	if key == "M1" and M1cooldown == true then
		M1cooldown = false
		local anim = plr.Character.Humanoid.Animator:LoadAnimation(plr.Character.Humanoid.Animator.Slash)
		anim.Priority = Enum.AnimationPriority.Action2
		anim:Play()
		task.wait(0.5)
		M1cooldown = true
	end
end)

That fixed it, thanks for all ye help :D!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.