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

How do I make this script target the player?

Asked by 6 years ago

I'm trying to make this admin thing

local command = script.Parent.Parent.TypeCmd
local playertocmd = script.Parent.Parent.TypePlr
local fire = Instance.new("Fire")
script.Parent.MouseButton1Click:connect(function()
    wait(0.1)
    if command.Text == "fire" then
        local playertext = playertocmd.Text
        fire.Parent = game.Players..playertext..CharacterAdded:wait().Head
        command.Text = "Command sent!"
        wait(1)
        command.Text = "Command"
        playertocmd = "Player"
                print("command")
    end
end)

Output Errors: 14:44:20.365 - Players.Player1.PlayerGui.AdminGUI.Admin.EnterCmd.LocalScript:9: attempt to index global 'CharacterAdded' (a nil value)

plez haelp

1 answer

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

alright so a few things to keep in mind. 1. Currently, you are not checking correctly. game.Players..playerText.. is not going to get you the player that has been typed. What you need to do is FindFirstChild or [playerText] - Let me explain why you're going to use FindFirstChild. 2. If they typed an invalid player, it will error. 3. This will not work if your game has Fe.

-- This code will not work if Fe is on!
local command = script.Parent.Parent.TypeCmd
local playertocmd = script.Parent.Parent.TypePlr
local debounce = true -- debounce is useful to prevent duplicates
script.Parent.MouseButton1Click:connect(function()
    if debounce and game.Players:FindFirstChild(playertocmd.Text) ~= nil and game.Players:FindFirstChild(playertocmd.Text).Character ~= nil then 
        -- the line above checks if the debounce is ready, if the player is in game, AND if the player's character is in workspace
        debounce = false
        if command.Text == "fire" then
            local fire = Instance.new("Fire") -- Make a different fire every time
            local player = game.Players:FindFirstChild(playertocmd.Text)
            fire.Parent = player.Character.Head
            command.Text = "Command sent!"
        elseif command.Text == "freeze" then -- Just added this to show you how to put more commands
            local player = game.Players:FindFirstChild(playertocmd.Text)
            player.Character.Humanoid.WalkSpeed = 0
        end
        wait(1)
        command.Text = "Command"
        playertocmd.Text = "Player"
        print("command")
        debounce = true
    end
end)

There might be an error from a typo because I just did this here, but it should get the message across. I hope you found this helpful, and have a nice day

0
thoinks moight bossay8 8 — 6y
0
Np iamnoamesa 674 — 6y
Ad

Answer this question