Dive stops working after the first death

i made a dive for my game, it ragdolls the character, uses pivotto to position them off the ground since being in contact with the ground reduces forces by like 99% for some reason, and use apply impulse to apply the force in the direction the character is facing

after dying for some reason the dash doesnt go anywhere, im pretty sure this has something to do with the code for the input running twice despite having a debounce, this isnt the case after you respawn though, itll only fire once like its supposed to, something else thats probably the main problem is that the apply impulse just generally feels weaker, first i thought maybe its just not going anywhere since the pivotto isnt placing it high enough in the air so its still grazing the floor, if i put the character 10 studs into the air the first life its fine, after you die once though the apply impulse doesnt take you anywhere

thanks for reading, not sure if anyone knows whats up with this

some notes
this script is a character script, the player character has been changed
and whenever the character dies i loop through the characterscripts in starter player
and parent them to the new character through characteradded, which is also
where the character is replaced with the new one,

heres the code for the dive

local userInputService = game:GetService("UserInputService")

local ragdoll = game.ReplicatedStorage.ragdoll

local player = game.Players.LocalPlayer
local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

--local raycasting = false

local cooldown = false

local spring1 = game.SoundService["spring1"]
local spring2 = game.SoundService["spring2"]

local springs = {spring1, spring2}

local rules = RaycastParams.new()
rules.FilterDescendantsInstances = {character}
rules.FilterType = Enum.RaycastFilterType.Exclude

userInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.LeftShift and humanoid:GetState() == Enum.HumanoidStateType.Running and not cooldown then
		cooldown = true
		--raycasting = true
		-- this is just so that in the time it takes to raycast you cant dive again

		--local result = workspace:Raycast(character.Torso.Position, Vector3.new(0,-4.5,0), rules)
		-- check if player is on ground
		-- for some reason this raycast breaks the debounce every other dive???

		--raycasting = false
		
		-- replaced raycasts with just checking if player is running


		local torso = character:WaitForChild("Head")
		local direction = torso.CFrame.LookVector + Vector3.new(0,0.5,0)
		-- i do this before i ragdoll in hopes of it going in the right direction

		ragdoll:FireServer()

		local mass = character.PrimaryPart.AssemblyMass

		character:PivotTo(character:GetPivot() * CFrame.Angles(math.rad(-40),0,0) * CFrame.new(0,12,0))
		-- position off the ground since if youre in contact with the ground
		-- forces do nothing, friction is crazy?
		
		--task.wait()
		
		print((direction * mass * 25).Magnitude)

		torso:ApplyImpulse(direction * mass * 25)
		springs[math.random(1,2)]:Play()

		task.wait(2)
		cooldown = false
	end
end)

heres a video of what happens

thanks to a friend, Star_Opener, this hasnt been fixed, but avoided as a whole, he suggested to load the character again after its been loaded in (basically respawning the player making it so the player was never on their first life) and boost up the values, also it really was just since it was firing twice the first life, not sure why it was doing that

regardless, if someone could tell me why this fired twice that would be helpful, thanks

If you mean what I think you mean - you explicitly iterate through the StarterCharacterScripts and assign them to the new character - then that would be your issue clear as day.

StarterCharacterScripts are automatically added to the Character every time you spawn. If you’ve added a script to add these scripts to the character, then you would have two of every script in there.

I think that explains it sufficiently(?)

through my experience i havent had this be the case, its probably since i replace the character with something else but i add them in since they arent added automatically, thanks for the response

image
heres a screenshot of the character scripts inside the character when this bug occurs

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