I'm wondering another way to access a LocalPlayer through a regular script, How would I go about doing this?
game.Players.LocalPlayer.MoneyValue
That's what I'm trying to do only through a Script, How would I accomplish this?
There's no way of doing this with a script without having no input from the player. If you have an input from a player, such as MouseClick
, Touched
, etc., then you can find the "local player."
One way of doing this is acquiring the name of the player through the event and finding the player.
Example 1
script.Parent.Touched:Connect(function(characterBodyPart) local characterName = characterBodyPart.Parent.Name -- Gets the name of the player that touched the object. local player = game.Players:FindFirstChild(characterName) -- Finds the player with that name and indexes it as 'player'. end)
You could also add a remote event in replicatedStorage and a local script in starterGui and call for the server from the individual player's client.
In Local Script
local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("RemoteEvent") local player = script.Parent.Parent remote:FireServer(player)
In Server Script
local repStorage = game:GetService("ReplicatedStorage") local remote = repStorage:WaitForChild("RemoteEvent") remote.OnServerEvent:connect(function(player) player.MoneyValue end)
Hope this helps