Script isn't triggering

For some reason, my script is not triggering when the player has a morph equipped, could anyone help please?

local character = plr.Character 
local Humanoid = character.Humanoid 

local timeScale = 3 

local gravity = 196.2 
local walkSpeed = 16 
local slowedWalkSpeed = walkSpeed/timeScale
local slowedGravity = gravity/(timeScale * 7)

function OnTouch()
	if character:FindFirstChild("Humanoid") then 
		if Humanoid ~= nil then 
			print("IT PRINTS")
			Humanoid.WalkSpeed = slowedWalkSpeed
		end
	elseif Humanoid.FloorMaterial == Enum.Material.Air then 

	end
end

game.Workspace.SlowMoStartPart.Touched:Connect(OnTouch)


function NewOnTouch()
	if character:FindFirstChild("Humanoid") then 
		if Humanoid ~= nil then 
			print("IT PRINTS AGAIN")
			Humanoid.WalkSpeed = walkSpeed
		end
	elseif Humanoid.FloorMaterial == Enum.Material.Air then 
	end
end

game.Workspace.CorridorExpulsionTrigger.Touched:Connect(NewOnTouch)```

Because the morph’s model is probably a different name from the character.

Where did you put this local script?

Maybe because the morph has changed the players humanoid, so you need to redefine the character.

Part.Touched:Connect(function(Hit)
	local Character
	if Hit.Parent:FindFirstChild("Humanoid") then
		Character = Hit.Parent
	elseif Hit.Parent.Parent:FindFirstChild("Humanoid") then -- hit was parent in an accessory
		Character = Hit.Parent.Parent
	end
	-- do your stuff
end)

The local script is placed inside StarterCharacterScripts

I’ll try it to see if it works, thank you.

Try this for your function;

function OnTouch(part)
	if part.Parent:FindFirstChild("Humanoid") then 
		if Humanoid ~= nil then 
			print("IT PRINTS")
			Humanoid.WalkSpeed = slowedWalkSpeed
		end
	elseif Humanoid.FloorMaterial == Enum.Material.Air then 

	end
end

game.Workspace.SlowMoStartPart.Touched:Connect(OnTouch(part))

Tried it but it isn’t working, i’ll try Gr8M8’s solution

This doesnt work but thank you

When you’re in the air look at the FloorMaterial property. It’s blank. Even though it’s not technically nil, I’m not sure you can reference it in the manner you want using “Air”. Which is weird since running “Print (Humanoid.FloorMaterial.Name)” will yield you “Air” in the output, but I’m guessing that’s the problem.

1 Like

Try this

local character = player.Character or player.CharacterAdded:Wait()

Cause the script needs to know the current character

You could also do this;

game.Workspace.SlowMoStartPart.Touched:Connect(function(part)
     if part.Parent:FindFirstChild("Humanoid") then 
		if Humanoid ~= nil then 
			print("IT PRINTS")
			Humanoid.WalkSpeed = slowedWalkSpeed
		end
	elseif Humanoid.FloorMaterial == Enum.Material.Air then 

	end
end)

This is what I always use and it works just fine.

Not working so its probably because the morph might not have the same rigType as player

It sadly didnt fix the issue, the problem might be the RigType

Can I see the explorer menu of the rig?

Starter player character rig or the morph’s character rig?

Which ever one your having the problems with.