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

What is wrong with my script?

Asked by
IcyEvil 260 Moderation Voter
10 years ago

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

Im trying to make it to where when you touch this brick you get kicked, But an error shows up saying

Touched/onTouched are not Valid Members of Part. ( Which is the parent.) Here is the Lines of code.

game.Players.PlayerAdded:connect(function(plr)
    script.Parent.onTouched = plr:Kick()
end)

Please Help.

2 answers

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

In English, this is what you want to do:

When a player touches a brick, they get kicked

We should formalize this a bit more:

When something touches a brick, if that something is a player's character, then kick that player


Note: there is nothing in that that would respond to a player joining. Think about the problem before you just write something down hoping it will work. It doesn't work like that.

Touched events are events, so they require a connection, just like your use of PlayerAdded.

They are not function values. Beside that, they would need to be a function: the Kick method returns nil so at best this script would be

  • kicks player upon entering
  • set onTouched to nil

When something touches a brick, if that something is a player's character, then kick that player

function onTouch(partTouching)
    if partTouching.Parent then
        local player =
            game.Players:GetPlayerFromCharacter(partTouching.Parent);
        if player then
            player:Kick();
        end
    end
end
script.Parent.Touched:connect( onTouch );
Ad
Log in to vote
1
Answered by 10 years ago

Touched is another event you have to formally call, just like PlayerAdded.

    script.Parent.Touched:connect(function(hit)
        if game.Players:GetPlayerFromCharacter(hit.Parent) == plr then
            plr:Remove()
        end
    end)

However, using PlayerAdded in conjunction with Touched is redundant in this case.

Answer this question