i was making an admin script, that when the localplayer types something in chat, they die, why wont this script work:
local p = game.Players:findFirstChild("UzL_z") p.Chatted:connect(function(message) local msg = string.lower(message) if string.find(msg, "kill") then game.Players.LocalPlayer.Character.Head:Remove() end end
(Roblox studio thinks the script is fine, it just dosent work)
(i am new to Lua scripting)
All right. I will give my opinion and hope it helps. I will write a script and comment what and why I did what I did.
local admins = {"UzL_z"} -- a table of admins in case you want to add more admins local players = game:GetService("Players") -- GetService is the recommended method for getting services like serverstorage, players, replicatedstorage and so on local function isAdmin(player) -- a function to determine if a player is in the admins table above for i,v in pairs(admins) do if v == player.Name then return true end end return false end players.PlayerAdded:Connect(function(player) -- an event like the Chatted event that fires everytime a player joins if isAdmin(player) then -- if the player is not an admin the script after this if statement will not run because the function returns false if the player is not an admin player.Chatted:Connect(function(message) local msg = string.lower(message) if string.match(msg, "kill") then -- string.find is used for getting the location of a match in a string. string.match is more what you are needing in this situation -- you could add an if statement here checking to see if the players humanoid exists. player.Character.Humanoid.Health = 0 -- I feel like this is a more effective way of killing the player. If you still want to do it the other way just know that :Remove() is deprecated and you should use :Destroy() instead. end end) end end)
Hope this helps and have a great day scripting!