Hey guys, I Am trying to make a script where you can join a job in my Roleplay game by clicking on a 'for hire' sign on the window of a business place, but i keep getting an error, can someone help me?
here is the script by the way
local job = false script.Parent.ClickDetector.MouseClick:connect(function(newplayer) game.Players.LocalPlayer.Character.Head.Job.JobTitle.Text = ("BlueMart Employee") job = true while true do game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + 75 wait (5) end end)
I Keep getting an error in the game, it says
Workspace.Job.Sign.Now Hiring:3 attempt to index field 'LocalPlayer' (a nil value)
You're attempting to call the Local Player
in a server script while the Local Player
can only be accessed via a local script. I recommend understanding the difference between a server script and local script using this very helpful wiki page, http://wiki.roblox.com/index.php/Client-Side_Scripting_and_Server-Side_Scripting . Now if in the future if you still are using the practice of attempting to call LocalPlayer in a server script, I recommend learning about remote events (through this wiki page https://wiki.roblox.com/index.php?title=Remote_Functions_%26_Events). But that is off topic. Basically, since you are unable to get the Local Player
inside the server script, I recommend replacing the Local Player with the newplayer
variable you set earlier. For example, you would use the code below replacing the Local Player,
game.Players[newplayer.Name].Character.Head.Job.JobTitle.Text = "BlueMart Employee" game.Players[newplayer.Name].leaderstats.Money.Value.Value = game.Players[newplayer.Name].leaderstats.Money.Value.Value + 75