Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-3

Making a variable of humanoid?

Asked by
jdflyer -9
8 years ago

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

Log in to vote
1
Answered by 8 years ago

Here is an example of finding the humanoid:

01local sp = script.Parent
02local h = 35
03local c = 5
04local d = true
05 
06sp.Touched:connect(function(part)
07    local char = part.Parent
08    local human = char:FindFirstChild("Humanoid") --Identifies the Humanoid
09    if human and d then
10        if human.Health > 0 and human.Health < human.MaxHealth then
11            d = false
12            local ch = human.Health
13            local nh = ch + h
14            human.Health = nh
15            sp.Transparency = .5
View all 23 lines...
Ad
Log in to vote
1
Answered by 8 years ago
Edited 8 years ago

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.

01--This script is parented to the part that is going to check if the player has a walkspeed of 25 or greater
02 
03local part = script.Parent
04local validWalkspeed = 25
05 
06part.Touched:Connect(function(hit)
07    local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
08    if player then
09        local humanoid = player.Character:WaitForChild("Humanoid")
10        if humanoid then
11            if humanoid.WalkSpeed >= validWalkspeed then
12                print(player .. " has a walkspeed greater than/equal to 25!")
13                part.CanCollide = false
14            else
15                print(player .. " doesn't have a walkspeed greater than/equal to 25!")
16            end
17        end
18    end
19end)
0
This pretty much answers your question. It does everything you wanted it to UltimateRaheem 75 — 8y

Answer this question