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

how do i fix my explode player command script?

Asked by 4 years ago

so i made an admin command script and this command is supposed to explode the player but it doesnt work. please help me

--//Explode Command
          if message:sub(1, 6) == "/explode " then
                    local TargetPlayer = game.Players:FindFirstChild(message:sub(7))
                    if TargetPlayer then
                        local Character = TargetPlayer.Character
                        if Character then
                            local ex = Instance.new("Explosion", game.Workspace)
                ex.Position = Character.Head
                        end
                    end
                end

full script

--//Admin Commands Script
--//Variables\\--
local DataStore = game:GetService("DataStoreService")
local BanList = DataStore:GetDataStore("BanList")
local Admins = {"omgdodogamer"} --//People who you want as admins

--//Events\\--
game.Players.PlayerAdded:connect(function(Player)
    local Folder = Instance.new("Folder", Player)
    Folder.Name = "PlayerValues"

    local BanCheck = Instance.new("BoolValue", Folder)
    BanCheck.Name = "IsBanned"
    BanCheck.Value = BanList:GetAsync(Player.userId) or false --//False is default if no save for the player

    --//Checks if the player is banned or not
    if Player.PlayerValues.IsBanned.Value == true then
        Player:Kick("You are banned from this game") --//Reason for kick
    end

    Player.Chatted:connect(function(message)
        for i, AdminName in ipairs(Admins) do
            if Player.Name == AdminName then
                --//Commands\\--
                --//Kill Command
                if message:sub(1, 6) == "/kill " then
                    local TargetPlayer = game.Players:FindFirstChild(message:sub(7))
                    if TargetPlayer then
                        local Character = TargetPlayer.Character
                        if Character then
                            Character.Humanoid.Health = 0
                        end
                    end
                end

          --//Explode Command
          if message:sub(1, 6) == "/explode " then
                    local TargetPlayer = game.Players:FindFirstChild(message:sub(7))
                    if TargetPlayer then
                        local Character = TargetPlayer.Character
                        if Character then
                            local ex = Instance.new("Explosion", game.Workspace)
                ex.Position = Character.Head
                        end
                    end
                end

                --//Kick Command
                if message:sub(1, 6) == "/kick " then
                    local TargetPlayer = game.Players:FindFirstChild(message:sub(7))
                    if TargetPlayer then
                        TargetPlayer:Kick("You have been kicked by " .. Player.Name) --//Kick message/reason
                    end
                end

                --//Ban Command
                if message:sub(1, 5) == "/ban " then
                    local TargetPlayer = game.Players:FindFirstChild(message:sub(6))
                    if TargetPlayer then
                        local BanCheck = TargetPlayer.PlayerValues.IsBanned
                        if BanCheck then
                            BanCheck.Value = true
                            BanList:SetAsync(TargetPlayer.userId, true)
                        end
                        TargetPlayer:Kick("You've been banned by " .. Player.Name) --//Reason || Message
                    end
                end

                --//Unban Command
                if message:sub(1, 7) == "/unban " then --//USES ID NOT NAME
                    local UserId = tonumber(message:sub(8))
                    if UserId then
                        BanList:SetAsync(UserId, false)
                    end
                end
                break
            end
        end
    end)
end)

im also pretty new to scripting, so expect mistakes

0
Use `:Connect` instead of `:connect` maumaumaumaumaumua 628 — 4y
0
IT WORKS :D omgdodogamer 11 — 4y
0
Thanks guys omgdodogamer 11 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

"/explode " is longer than 6 characters so it doesn't pass your if statement.

local myMessage = "/explode "
print(myMessage:sub(1, 6))

-- Output: /explo

You would need to change this the second parameter in :sub() to the correct length of the string.

NOTE: You would have to do this for other commands you add as well since not all commands your going to have a length of 6.

Try this instead:

if message:sub(1, 9) == "/explode " then
    local TargetPlayer = game.Players:FindFirstChild(message:sub(10))
end
Ad
Log in to vote
0
Answered by 4 years ago

You're using Explosion.Position = Head, you're basically setting the explosion's position to an object, to fix this replace

ex.Position = Character.Head

to

ex.Position = Character.Head.Position

Also, i recommend using WaitForChild or FindFirstChild because there are cases in wich the parts or objects don't exist.

If this answered your question mark it as the answer!

0
maumaumaumaumaumaumau, i tried it but it didnt work. oh and maybe you can say where i should put "FindFirstChild" Because i dont know since i am new at scripting omgdodogamer 11 — 4y
0
you use find first child on an object. ex: workspace.Part would be workspace:FindFirstChild("Part") maumaumaumaumaumua 628 — 4y

Answer this question