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

How to get object as a string from a table?

Asked by
fardxD 9
4 years ago

I'm trying to make an admin script for Void SB, I've gotten all the basics done! Unfortunately, I have run into a roadblock.

I don't know how to get a player from a string! this is super important, and vital for all admin scripts. So, please tell me, how do I get a player from a string?

here is the script:

local cmds = {"t!kill"}

owner.Chatted:Connect(function(msg)
    if msg:match(cmds[1]) then
         local s = msg:split(" ")
     e = s[2]
    game.Players.e.Character:BreakJoints()

end

end)

2 answers

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago
local cmds = {
    ["!kill"] = function( Admin, Split )
        -- If Player supplied/second string and is a player
        local Player = Split[2] and GetPlayer ( Split[2] ) 
        if Player and Player.Character then 
            Player.Character:BreakJoints()
        end
    end
}

--> So case doesn't matter 
function GetPlayer ( fromStr )
    for _, Player in pairs ( game.Players:GetPlayers()) do 
        if fromStr:lower() == Player.Name:lower() then 
            return Player 
        end
    end
    return false
end

game.Players.PlayerAdded:Connect(function ( Player ) 
    Player.Chatted:Connect(function(msg)
        --> lowercase and split strings
        local Split = msg:lower():split(' ')
        --> If Split[1] and Split[1] is in cmds
        local Command = Split and Split[1] and cmds[ Split[1] ]
        if Command then
            Command( Player, Split )
        end
    end)
end)
Ad
Log in to vote
-1
Answered by 4 years ago
Edited 4 years ago

Try this:

local cmds = {"t!kill"}

owner.Chatted:Connect(function(msg)
    if msg:match(cmds[1]) then
         local s = msg:split(" ")
     e = s[2]
    game.Players[e]Character:BreakJoints() -- To get an object with it's name as a string we replace its name with: [ Object name here] 

end

end)
0
Incomplete statement: expected assignment or a function call fardxD 9 — 4y
0
at what line? FirewolfYT_751 223 — 4y
0
oups dionsyran2 66 — 4y
0
i updated it, try it and tell me if it works dionsyran2 66 — 4y

Answer this question