Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Making a variable of humanoid?

I need to have a part identify the player's walkspeed for it to turn off CanCollide. I must do this by locating the player's humanoid.

2 answers

✓ Accepted answer

Here is an example of finding the humanoid:

local sp = script.Parent
local h = 35
local c = 5
local d = true

sp.Touched:connect(function(part)
	local char = part.Parent
	local human = char:FindFirstChild("Humanoid") --Identifies the Humanoid
	if human and d then
		if human.Health > 0 and human.Health < human.MaxHealth then
			d = false
			local ch = human.Health
			local nh = ch + h
			human.Health = nh
			sp.Transparency = .5
			sp.CanCollide = false
			wait(c)
			sp.Transparency = 0
			sp.CanCollide = true
			d = true
		end
	end
end)

Okay, I'm going to make a part's cancollide change to false if they player touching it has a walkspeed of 25 or greater.

--This script is parented to the part that is going to check if the player has a walkspeed of 25 or greater

local part = script.Parent
local validWalkspeed = 25

part.Touched:Connect(function(hit)
	local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
	if player then
		local humanoid = player.Character:WaitForChild("Humanoid")
		if humanoid then
			if humanoid.WalkSpeed >= validWalkspeed then
				print(player .. " has a walkspeed greater than/equal to 25!")
				part.CanCollide = false
			else
				print(player .. " doesn't have a walkspeed greater than/equal to 25!")
			end
		end
	end
end)

1 comment

0

This pretty much answers your question. It does everything you wanted it to

This discussion is preserved as it was. New answers, comments, and votes are closed.