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

[SOLVED] How would I find the local player? [Read desk]

script.Parent.MouseClick:Connect(function()
	game.Players.LocalPlayer.PlayerGui.Stats.Hunger_Stat.Hunger_Amount = game.Players.LocalPlayer.PlayerGui.Stats.Hunger_Stat.Hunger_Amount + 25 
end)

It says local player wasnt found, but i need the food to go to only the local players Gui, anybody know how to do this?

Im using a non local script, and the script is inside the parent.

1 answer

✓ Accepted answer

I think you are using a ClickDetector. There are a couple of things to note down:

  • You can only use the LocalPlayer in a localscript that is inside the player, startergui etc.
  • The MouseClick Event for the ClickDetector comes with a parameter “player” which gives the player that clicked.
  • If you are making a hunger eating system it may be important to include Debounce.

Anyways let’s dive in. So basically your getting the LocalPlayer from a script in workspace. You can never get the LocalPlayer that way, you can only get it in a LocalScript that is under the various player folders like StarterGui, StarterPack, etc.

But since you are using a ClickDetector, it comes with a parameter that tells you which player clicked. I’ll provide a roblox link for events and such.

Your script fixed should be:


script.Parent.MouseClick:Connect(function(Player)
    game.Players.Player.PlayerGui.Stats.Hunger_Stat.Hunger_Amount = 	game.Players.Player.PlayerGui.Stats.Hunger_Stat.Hunger_Amount + 25 
end)

You can ask questions any time in the comments

3 comments

0

https://developer.roblox.com/en-us/articles/events Here’s a link for roblox events. I think you might understand, tell me if you don’t.

0

Hmm, thanks

0

No problem

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