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:

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)

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.

--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)
0
This pretty much answers your question. It does everything you wanted it to UltimateRaheem 75 — 8y

Answer this question