✓ Accepted answer
#Ancestry
The top ancestor (excluding the DataModel and the Players service) of a LocalScript is typically the LocalPlayer. You could also place them in ReplicatedFirst but we aren't going to talk about that. And LocalScripts run for one client, you. Scripts run on the server, which is responsible for connecting the players together in your game.
#Why LocalPlayer is nil on the server
Think of it as your school classmates and your teacher. Think of your school classmates as other clients, and think of your teacher as the server. If you told your teacher to get the local student, your teacher would be very confused, because which student is the local student? For this reason, LocalPlayer is nil on the server. Your game could have multiple players in it, and when you try using LocalPlayer, it can't just randomly pick a player. It makes no sense.
#Code doesn't read minds
Code cannot read your mind. This is why it must be all typed out. So instead of doing this:
make a part inside of the workspace with color red
You must do this:
local part = Instance.new("Part")
part.BrickColor = BrickColor.new("Really red")
part.Parent = workspace
#Fix
With that in mind, let's fix your script. Since you are using MouseClick with a ClickDetector, this will be easy. The MouseClick event gives us the Player who clicked as a parameter, and you have named it Clicker, so let's use that.
script.Parent.ClickDetector.MouseClick:Connect(function(Clicker)
if Clicker:GetRankInGroup(3863824)== 254 then
local clone = script.Parent.Gui:Clone()
clone.Parent = Clicker.PlayerGui
end
end)
And finally, Event:connect() is deprecated, use Event:Connect().
3 comments
Is this a regular script? If so it’s because it doesn’t know LocalPlayer, that should be for local script purposes.
Are you using a server script again? And I am using Clicker because MouseClick passes the player who clicked the click detector. It can be named anything you want, and you have named it clicker so I used that.
No, I am using a local script.