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

how could i access the player from a touched event?

Asked by 6 years ago
Edited 6 years ago

i don't mean like the player model i mean the actual player in the players tab under workspace if i started from script.Parent.Touched:Connect(function(hit)

i thought it might be this but this code doesn't work, it says retracee is not a valid member of players, even though I see myself in the players..?

script.Parent.Touched:Connect(function(hit) 
    local plr = hit.Parent
    game.Players(plr.Name):Destroy()

    end)



then I tried this but I got lost and didn't know how to access the player who had the Id, also it seems like it can't see my userid from a touched event because the logs say userid is not a valid member of model

local players = game:GetService("Players")

script.Parent.Touched:Connect(function(hit) 
    local plr = hit.Parent
    local player1s = players:GetChildren()
    if player1s.CharacterAppearanceId == plr.UserId then
        player1s:Destroy()
    end

    end)

1 answer

Log in to vote
2
Answered by
RAYAN1565 691 Moderation Voter
6 years ago
Edited 6 years ago

This is what you would have to do:

script.Parent.Touched:Connect(function(hit) 
    local player = game.Players:GetPlayerFromCharacter(hit.Parent) --is the part touching a player or another part?
    if player then --if it is a player that touched the part, then continue...
         player:Destroy() --you have the player pulled out right here, now what do you want to do with this information... write your function here... do you want to destroy your player? do you want to change the player's name? All of what you are trying to do goes here.
    end
end)

This script would display the player's name in the output.

0
that's not what im trying to do:( retracee 68 — 6y
1
Basically, line 2 is just getting the player from the part that touched the object the script is placed under. If it cannot get the player, that means it wasn't touching the character, it was touching something else (i.e. the baseplate). If it can get the player, then it continues to run by means of the if then function. RAYAN1565 691 — 6y
1
What are you trying to do? RAYAN1565 691 — 6y
0
under workspace in the directory, theres a category marked players, I want to know how to pick out a player if they touch a brick retracee 68 — 6y
View all comments (3 more)
1
I just did it... RAYAN1565 691 — 6y
0
i meant, i want to access their player in the players tab under workspace if they touch a brick retracee 68 — 6y
0
nevermind haha you were right i confused myself sorry retracee 68 — 6y
Ad

Answer this question