I know there are some ways like:
for _,plr in pairs(game.Players:GetPlayers()) do end -------------------------------- local plr = game:GetService("Players").LocalPlayer -- Never works.
Need it for this script.
local VIP = require(script.Parent); local debounce = false; local market = game:GetService("MarketplaceService"); local ID = VIP.infromation.vipID; VIP.infromation.obj.portal.Touched:Connect(function(hit) local player = nil;-- What do I put here> if market:UserOwnsGamePassAsync(player.UserId,ID) then if not debounce then debounce = true if hit.Parent.Character ~= nil then hit.Parent.Character:moveTo(VIP.infromation.obj.enter.front) wait(1) debounce = false end end end end)
1) the use of remote events' FireServer() function and the OnServerEvent() event
--local script local remote = game.ReplicatedStorage.RemoteEvent remote:FireServer() --server script local remote = game.ReplicatedStorage.RemoteEvent local player remote.OnServerEvent:Connect(function(plr) ... end)
2) the use of the :GetPlayerFromCharacter() function
script.Parent.Touched:Connect(function(hit) local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then ... end end)
3) the PlayerAdded event
game.Players.PlayerAdded:Connect(function(player) ... end
4) the PlayerRemoving event
game.Players.PlayerRemoving:Connect(function(player) ... end
5) indexing a player in the list of players
local plrs = game.Players:GetPlayers() local plr = plrs[math.random(1,#plrs)]
Easy!
Make a Local Script or use RemoteEvents :)