I’m totally baffled by this situation:
I’ve been creating a simple admin past hour and I can’t seem to bypass this weird problem I’m getting
function for getting the player’s full name
local function findplayer(plr, part)
if part ~= nil then
if string.lower(part) == "me" then
return plr.Name
else
local v = nil
for _, v in pairs(game.Players:GetChildren()) do
for i, j in ipairs(v.Name:split("")) do
if string.lower(part) == string.lower(v.Name:sub(1, i)) then
return v
end
end
end
end
else
return nil
end
end
script for the walkspeed command
local playername, speedval = string.match(msg, "^:walkspeed%s+(%S+)%s*(%d+)$")
local shouldberealname = findplayer(plr, playername)
-- name should always exist
if shouldberealname ~= nil and tonumber(speedval) >= 0 then
print(shouldberealname)
print(speedval)
game.Workspace:FindFirstChild(shouldberealname):WaitForChild("Humanoid").WalkSpeed = tonumber(speedval)
else
displayerror("Wrong Approach")
end
when I perform
:walkspeed me 100, it works totally fine.
However,
:walkspeed sp 100 continued to error with the following:
ServerScriptService.sparkleadmin.command:40: attempt to index nil with 'WaitForChild'
So I thought it had something to do with my findplayer function not working so as you can see, in my main script I added
print("shouldberealname")
The first 2 line of the console is me doing :walkspeed me 100
Rest of the lines(including the error) are me doing :walkspeed spa 100
It surely fetches my player’s name well and I do not see the problem at al.