Player being tped for no reason

I have this which is suppose to give a player a tail

RunService.Heartbeat:Connect(function()
	local HumanoidState = Humanoid:GetState()
	
	if HumanoidState == Enum.HumanoidStateType.Swimming then
		if not Character:FindFirstChild('Tail') then
			local Clone = Tail:Clone()
			Clone.Name = 'Tail'
			print(Clone)
			
			local Weld = Instance.new('Weld')
			Weld.Name = 'Weld'
			Weld.Part0 = Character.LowerTorso
			Weld.Part1 = Clone.PrimaryPart
			Weld.C0 = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(180), 0, 0)
			Weld.C0 = Weld.C0
			Weld.Parent = Clone
			print(Clone, 2)
			Clone.Parent = Character
			print(Clone.Parent, Character)
		end
end)

This is what it does to me


So it works great on my character, however for other players it just tps them to a random spot and they fall to their death

Even tho it prints this for them


Which means it should work, however it isn’t. When I’ve done TeamTest, they don’t get given the model, their character just tps to the middle of nowhere and dies.

The error is occuring in this chunk of code too, as removing this doesn’t tp the player when they enter the water

this wont fix your error but why are you running this every heartbeat instead you can just detect when the humanoid state changes, there is the event here https://developer.roblox.com/en-us/api-reference/ev.

--this is how you use it 
humanoid.StateChanged:Connect(function(oldState,newState)
     if newState == Enum.HumanoidStateType.Swimming then
         --swimming stuff here
     end
end
1 Like

oh and is this being done on the server or the client, cuz it should be on the server

1 Like

Client… why should it be done on the server??

to make sure the changes replicate because of FE (filtering enabled)

Hmm ok, well I transferred it to the server, but same thing still applies :confused:

function TailService:EquipTail(player, newState, character)
	local User = PlayerData[player.UserId]
	if not User then return end
	
	local Tail = Tails:FindFirstChild(User.Tail)
	if newState == Enum.HumanoidStateType.Swimming then
		character.LeftFoot.Transparency = 1
		character.RightFoot.Transparency = 1
		character.RightUpperLeg.Transparency = 1
		character.RightLowerLeg.Transparency = 1
		character.LeftUpperLeg.Transparency = 1
		character.LeftLowerLeg.Transparency = 1
		
		if not character:FindFirstChild('Tail') then
			local Clone = Tail:Clone()
			Clone.Name = 'Tail'
			
			local Weld = Instance.new('Weld')
			Weld.Name = 'Weld'
			Weld.Part0 = character.LowerTorso
			Weld.Part1 = Clone.PrimaryPart
			Weld.C0 = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(180), 0, 0)
			Weld.C0 = Weld.C0
			Weld.Parent = Clone
			
			Clone.Parent = character
		end
	else
		if character:FindFirstChild('Tail') then
			character.LeftFoot.Transparency = 0
			character.RightFoot.Transparency = 0
			character.RightUpperLeg.Transparency = 0
			character.RightLowerLeg.Transparency = 0
			character.LeftUpperLeg.Transparency = 0
			character.LeftLowerLeg.Transparency = 0
			
			character.Tail:Destroy()
		end
	end
end

is the Clone anchored because it shouldnt be, try making it setting anchored to false

None of the parts of Clone are Anchored and all parts are CanCollide false

Where are the script and model placed?

script is inside ServerScriptService and model is under a folder in RepStorage

Hi I noticed in your script you are setting the C0 to itself. Is there a reason you are doing this or just mistype?

  	Weld.C0 = CFrame.new(0, 0, 0) * CFrame.Angles(math.rad(180), 0, 0)
  	Weld.C0 = Weld.C0

Maybe try

Weld.C1 = Weld.C0

Also you may want to move the tail to the players position before adding to workspace. This can help to keep the character from being moved toward the tail in game. Which I have had some issues with in my games

Clone:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
Clone.Parent = character

Can you post the line that defines “Tails”?
How are the welds set up on the tail model itself?

Does this occur in studio with simulated clients and on an actual server?

I had an issue similar to this a while ago attaching backpacks to the player. The tail is just a model, right? It might be better to use an accessory and attachment.

Doing this causes this to happen

I think your parts are anchored. Try unanchoring them

Did this stop the character from being teleported?