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

How to get object as a string from a table?

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

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)

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)

4 comments

0

Incomplete statement: expected assignment or a function call

0

at what line?

0

oups

0

i updated it, try it and tell me if it works

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