Hello, i have an issue with a script. I want to get a specific team of a person that steps on a block to add on a value, The issue is that i cannot get the team of the player, i get the error “Team is not a valid member of Part Workspace.giorgos2020_new.Left Leg(or Right Leg)”
ive tried searching for any solutions here but could not find any. here is the current script:
local siCount = game.Workspace.Values.AmountofSI_inRestraunt
local FDACount = game.Workspace.Values.AmountofFDA_inRestraunt
script.Parent.Touched:Connect(function(plr)
if plr.Team ~= "Safety Inspector" or "FDA Agent" then return end
if plr.Team == "Safety Inspector" then
siCount += 1
end
if plr.Team == "FDA Agent" then
FDACount += 1
end
end)
i appreciate any help and feedback, thanks!
1 Like
.Touched does not return a player, it returns the part that touched it
1 Like
then, what should i use instead of .Touched?
1 Like
Nothing different, youll just need to get the player from the part. Which if you look it up there are plenty of tutorials on it that will probably explain it better than me
1 Like
According to this post, you can use the part’s parent → get the player’s model (character) → get the player
part.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if player then
-- do stuff
end
end)
@giorgos2020_new Edit (for more clarity compared to cited post’s code)
local PlayersService = game:GetService("Players")
part.Touched:Connect(function(hit)
local character = hit.Parent
local player = PlayersService:GetPlayerFromCharacter(character)
if player then
-- Your code about the team stuff here.
-- I made some optimizations for your code too.
if plr.Team == "Safety Inspector" then
siCount += 1
elseif plr.Team == "FDA Agent" then
FDACount += 1
end
end
end)
2 Likes
Like what the people below me have said, .touched
only returns a part, not a player.
Second of all, the Team
value of the player is an object, not a string, and you are checking if the team (object) is equal to a string. Instead, check if the plr.Team.Name == "team name"
.
1 Like