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

forcefield function doesnt work? [closed]

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.

its suppose to be a script that gives you a permanent forcefield around your player so you can never die but it doesn't really work. :/

function newPlayer(player)
    local ff = Instance.new("ForceField")
    ff.Parent = player.Character.Torso
end

game.Players.PlayerAdded:connect(newPlayer)

Locked by EzraNehemiah_TF2 and BlueTaslem

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

2 answers

Log in to vote
4
Answered by 9 years ago

Force Fields don't go inside the player's torso. It only goes inside the character:

function newPlayer(player)
    local ff = Instance.new("ForceField")
    ff.Parent = player.Character
end

game.Players.PlayerAdded:connect(newPlayer)


Also, did you know that Instance.new() has 2 arguments? The object and the parent! So line 3 isn't needed.

function newPlayer(player)
    local ff = Instance.new("ForceField", player.Character) --Notice the "player.Character"
end

game.Players.PlayerAdded:connect(newPlayer)

EDIT

Like how the Jash50 said. Maybe the character hasn't been added yet because this script runs when the player joins the game. But when this happens the game isn't fully loaded for that player. Use this script to wait until the character is loaded.

game.Players.PlayerAdded:connect(function(plyr)
    plyr.CharacterAdded:connect(function(char) --Wait for the character to be added.
        local ff = Instance.new("ForceField", char)
    end)
end)

Also, if the player dies the character is added again so the function is triggered again. You don't need to have any Died event here.

0
Okay then. EzraNehemiah_TF2 3552 — 9y
0
still doesn't work alex_ander 163 — 9y
0
I tried it and it still never worked alex_ander 163 — 9y
Ad
Log in to vote
2
Answered by
Jash50 5
9 years ago

Maybe the character doesn't loaded yet.. so you can make it like this:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        local ff = Instance.new("ForceField")
        ff.Parent = character.Torso
    end)
end)

Edit:

This should work:

game.Players.PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        local ff = Instance.new("ForceField", character)
    end)
end)
0
It is in a regular script. If it were a local script, maybe that would be true, but local scripts can't use the PlayerAdded event. EzraNehemiah_TF2 3552 — 9y
0
It works in regular script because I tested it already xD. As you said, ff can't put in torso but can only be put in character. :) Jash50 5 — 9y
0
What I'm trying to say is local scripts run before the game is even fully loaded. EzraNehemiah_TF2 3552 — 9y