Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

how to let a remote event use a localplayer?

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("UpgradeEvent")
local Pcframe = game.Players.LocalPlayer.PlayerGUI.Gui.Shopframe

local function Buy()
	if game.Players.LocalPlayer.leaderstats.Pc.Value == 0 then
	game.Players.LocalPlayer.leaderstats.Cash.Value = game.Players.LocalPlayer.leaderstats.Cash.Value - 1000
	game.Players.LocalPlayer.leaderstats.Pc.Value = game.Players.LocalPlayer.leaderstats.Cash.Value + 1
	Pcframe.buy.Text = "Pc Maxed Out"
	Pcframe.buy.BackgroundColor3 = Color3.fromRGB(186, 0, 0)
	Pcframe.buy.Frame.BackgroundColor3 = Color3.fromRGB(147, 0, 0)
	end	
end

remoteEvent.OnServerEvent:Connect(Buy)

This is my remote event script I need it else my datastore won't update but how to let the remote event use a local script cause the remote event needs to be in a normal script?

1 answer

Hello, hokyboy!

There is no way you can call LocalPlayer in a normal script, but yes you can get it a different way by doing

ocal ReplicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = ReplicatedStorage:WaitForChild("UpgradeEvent")

remoteEvent.OnServerEvent:Connect(function(plr)

end)

plr would technically be the LocalPlayer so you can do things like plr:WaitForChild("leaderstats").IDK.Value

This discussion is preserved as it was. New answers, comments, and votes are closed.