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.
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 connect
ion, 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
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 );
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.