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

Can't seem to find the humanoid, advice?

Asked by 9 years ago

This is a admin script I am making the kill/ function works. Just not the freeze/ it generates no errors and I can't seem to figure it out. Advice or help would be grateful :D

script.Parent = nil
local Owners = {["Player"] = true}
function findPlayer(name)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
        end
    end
end

function onChatted(message, player)
    if message:sub(1, 5) == "kill/" and Owners[player.Name] then
        victim = findPlayer(message:sub(6))
        if victim and victim.Character then
            victim.Character:BreakJoints()
        end
    end
end

function onChatted2(message, player)
    if message:sub(1, 5) == "freeze/" and Owners[player.Name] then
        victim = findPlayer(message:sub(6))
        if victim and victim.Character then
            victim.Character.Humanoid.Walkspeed = 0  -- It can't seem to find the humanoid to turn off the walkspeed
        end
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player)  end)
    player.Chatted:connect(function(message) onChatted2(message, player) end)
end)
0
The WalkSpeed property is spelled with a capital S. FearMeIAmLag 1161 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

/freeze is longer than /kill make sure you sub the right amount!

script.Parent = nil
local Owners = {["Player"] = true}
function findPlayer(name)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.Name:lower() == name:lower() then
            return player
        end
    end
end

function onChatted(message, player)
    if message:sub(1, 5) == "kill/" and Owners[player.Name] then
        victim = findPlayer(message:sub(6))
        if victim and victim.Character then
            victim.Character:BreakJoints()
        end
    end
end

function onChatted2(message, player)
    if message:sub(1, 7) == "freeze/" and Owners[player.Name] then -- freeze/ is longer than kill/
        victim = findPlayer(message:sub(8))
        if victim and victim.Character then
            victim.Character.Humanoid.WalkSpeed = 0  -- It can't seem to find the humanoid to turn off the walkspeed
        end
    end
end

game.Players.PlayerAdded:connect(function(player)
    player.Chatted:connect(function(message) onChatted(message, player)  end)
    player.Chatted:connect(function(message) onChatted2(message, player) end)
end)

0
Thanks :) BinaryResolved 215 — 9y
Ad

Answer this question