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

Can't seem to find the humanoid, advice?

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)

1 comment

0

The WalkSpeed property is spelled with a capital S.

1 answer

✓ Accepted answer

/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)

1 comment

0

Thanks :)

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