Hey there,
I have this script here that is meant to insert a players name into the table when they touch a part. I’m only up to inserting a test word into the table which isn’t even working.
Help is greatly apricated
local sign = script.Parent
local Gplrs = {}
--table.insert(Gplrs)
sign.Touched:Connect(function(touching)
print("1")
table.insert(Gplrs, "Name")
print("2")
wait(5)
print(Gplrs[1])
end
I think you could just simply use the GetPlayerFromCharacter function, which basically detects if the part that got touched is equal to a Player’s Character Model so that you can insert the Name into:
local Sign = script.Parent
local Gplrs = {}
sign.Touched:Connect(function(Hit)
local Player = game.Players:GetPlayerFromCharacter(Hit.Parent)
if Player and not table.find(Gplrs, Player.Name) then
table.insert(Gplrs, Player.Name)
wait(5)
print(Gplrs[1])
end
end)
Although do keep in mind that this would only print the first player that touched it, anyone else who touches it would keep printing that same first player
local Gplrs = {}
sign.Touched:Connect(function(touching)
if touching and touching.Parent and touching.Parent:FindFirstChild("Humanoid") then -- checks if player
local plr = touching.Parent:GetPlayerFromCharacter()
Gplrs[#Gplrs+1] = plr.Name
end
end)
Oh nvm Im getting an error now, Here it is: “GetPlayerFromCharacter is not a valid member of Model “Workspace.JackFr_ost” - Server - Script:6”
And here’s my script:
local sign = script.Parent.Parent
local Gplrs = {}
sign.Touched:Connect(function(touching)
if touching and touching.Parent and touching.Parent:FindFirstChild("Humanoid") then -- checks if player
local plr = touching.Parent:GetPlayerFromCharacter()
Gplrs[#Gplrs+1] = plr.Name
end
end)
Maybe because the player model and player uses the same name, you can just get the character name instead of the player?
can you try this
local sign = script.Parent.Parent
local Gplrs = {}
sign.Touched:Connect(function(touching)
if touching and touching.Parent and touching.Parent:FindFirstChild("Humanoid") then -- checks if player
local plr = touching.Parent
Gplrs[#Gplrs+1] = plr.Name
end
end)
You’re getting the error because the function GetPlayerFromCharacter is a function inside of the Player model, not the individual character;
local sign = script.Parent.Parent
local Gplrs = {}
sign.Touched:Connect(function(touching)
if touching and touching.Parent and touching.Parent:FindFirstChild("Humanoid") then -- checks if player
local plr = game:GetService("Players"):GetPlayerFromCharacter(t.Parent)
Gplrs[#Gplrs+1] = plr.Name
end
end)
GetPlayerFromCharacter is a function of the player service, do game:GetService("Players"):GetPlayerFromCharacter(touching.Parent) instead
EDIT: @lanjtlike just saw your post ;-;