I need to access the LocalPlayer from a Script in the workspace. Is there any way to do this? On any code I try, I always get a return of nil when trying to access LocalPlayer.
Note that everything works fine besides accessing the LocalPlayer
My (attempted) RemoteEvent Script code:
ReplicatedStorage = game:GetService("ReplicatedStorage")
createPartEvent = Instance.new("RemoteEvent", ReplicatedStorage)
createPartEvent.Name = "HotDog"
player = game.Players.LocalPlayer
local function onCreatePartFired(player)
player.leaderstats.Cash.Value = player.leaderstats.Cash.Value + 1
end
createPartEvent.OnServerEvent:Connect(onCreatePartFired)
The LocalScript that calls the RemoteEvent Script:
function Click()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local createPartEvent = ReplicatedStorage:WaitForChild("HotDog")
createPartEvent:FireServer()
print ("Fired Successfully")
end
script.Parent.MouseButton1Click:connect(Click)

1 comment
Good Lord, you are the biggest life saver in the history of this website