Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago
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

Log in to vote
0
Answered by 4 years ago

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

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. 123nabilben123 499 — 4y
0
Hmm, thanks killerbrasko2002 33 — 4y
0
No problem 123nabilben123 499 — 4y
Ad

Answer this question