Hello, So I’m currently trying to get the local player in a normal script. Normally you can do but Is it possible to make a variable to get the player without having to use a function? or a remote event?
via a touched even in a normal script, you have to use the GetPlayerFromCharacter Function:
thing.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
end)
As if a player touched a part, the part(s) of the player touching the part are the parts picked up by the touched event that part, as it is a bodypart, would be a Child of the Player’s Character
script.Parent.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
-- blah blah blah
else
-- no humanoid found
--blah blah blah
end
end)
Hiya. So I looked at the thread but I"m slightly confused. I’m trying to get the player with a variable like this
local Player = (“What command Can I put here to get the player?”)
You don’t need to check for the humanoid before retrieving the player. This code works the same as your code:
script.Parent.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
-- player exists
else
-- player does not exist
end
end)
@ZoomCode The code above will get the player (plr) when script.Parent.Parent is touched.
Scripts run on the server. LocalScripts run on the client (each player). You can’t really get the local player to the server, as which one would you pick?
Well, that really depends on what you are trying to do, are you trying to get all players, are you trying to get a player if they have specifications, or are you just trying to get a specific player because you want that player and not any other player
The problem is that the server doesn’t have the concept of a local player, its like telling a parent to get their “local kid” or a teacher to get their “local student”
It wouldn’t make any sense, and they would be very confused by it
Are you trying to make the change on all Players’ backpacks, or are you trying to change it on a condition?
if its being done from a local script then you just do this:
local player = game.Players.LocalPlayer
else if your doing it on a server script you can use the playerAdded event
game.Players.PlayerAdded:Connect(function(player--[[this is the player variable]])
Status = script.Parent
Status.Changed:Connect(function()
if Status.Value == 1 then
print(Player.Name)
end
end
end)
but could you explain what do you need it on for a server script because there is most likely a far better solution of doing this.