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

What am I doing wrong?

Asked by 9 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I really wanted to start scriping, so I loaded up output and command bar and typed out

game.Workspace.harleyb09.Head:Destroy()

And it did nothing, not even tell me what was wrong. (I was in play solo) I also tried

game.Workspace.Player1.Head:Destroy()

But still, nothing happened. I feel like such a loser because my first ever script went wrong, please help.

0
The 2nd script works just fine for me. gskw 1046 — 9y

3 answers

Log in to vote
1
Answered by 9 years ago

Use this:

function removeHead(plr) --"removeHead is how I chose to name the function and "plr" is the how I chose to name the argument. In this case the event "PlayerAdded" takes the player as an argument.
    repeat wait() until plr.Character --Loop that repeats the wait() action until the player's character is ready
    wait(1) --Wait 1 second (added it so it will work for sure)
    if plr.Character.Name == "Name Here" then --Put player name here
        plr.Character.Head:Destroy() --Destroy head
    end
end

game.Players.PlayerAdded:connect(removeHead) --Calling the function using a connection line which contains the PlayerAdded event

I think your scripts didn't work because they were executed before the player even joined the game.

The following script runs a function once a player entered the game.

You will learn more about functions, if statements and loops in the future.

Haven't scripted in RBX.LUA for a few months now but I think it should work.

0
Wonderful. harleyb09 5 — 9y
0
Interesting how the script was executed before the player even joined the game when OP was using command bar.. Well +1 for explaining all the code properly. juzzbyXfalcon 155 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

The first one does not work because if you are in play solo mode, you will spawn as Player1. It worked for me. Also, don't feel upset, it'll come with time :).

0
The #2 worked for me. x3 DevSp4c3 0 — 9y
Log in to vote
0
Answered by 9 years ago

If it is still not working, try this:

game.Players.LocalPlayer.Character.Head:Destroy()

Keep in mind, if you were to place this in a server sided script it will not work. But since you're only beginning to script and you're just using the output it will do just fine.

0
Still doesn't work harleyb09 5 — 9y

Answer this question