Unable to give player leaderstats points

I have created an NPC which upon touched with the correct tool will move, it’s working correctly apart from the point giving segment. I have tried:

game.Players.LocalPlayer.leaderstats.WorkerPoint.Value = game.Players.LocalPlayer.leaderstats.WorkerPoint.Value + 1

Although it is erroring me with “leaderstats is not a valid member of NPC” This is inside the script highlighted below.

image

I first thought of using Remote Events but I cannot fire the server, any ideas?

Alright a side note:

  • Server Script: You can’t define game.Players.LocalPlayer that way, it just isn’t possible

    • The reason for this being is cause this is handled on the server, so how would the script know where to find the Local Player?

Could we actually see the full script to see what can be done about it?

local NPC = script.Parent.Parent
local FoodFOlder = game.ReplicatedStorage.Order_Possible
local AvabFood = FoodFOlder:GetChildren()
local ChosenFood = AvabFood[math.random(1,#AvabFood)]
local hitting = ChosenFood.Name
local NPCActive = game.ReplicatedStorage.NPC_Possible
local AvabNPC = NPCActive:GetChildren()
local ChosenOne = AvabNPC[math.random(1,#AvabNPC)]
local Online = ChosenOne

	wait(5)
	NPC.Humanoid:MoveTo(game.Workspace.NPCA.Point1.Position)
	NPC.Humanoid.MoveToFinished:Wait()
	wait(0)
	NPC.Humanoid:MoveTo(game.Workspace.NPCA.Point2.Position)
	NPC.Humanoid.MoveToFinished:Wait()
	wait(0)
	NPC.Humanoid:MoveTo(game.Workspace.NPCA.Point3.Position)
		--checks that correct was given
	NPC.Head.Order.order.Text = "Hi! Can I have a "..ChosenFood.Name.." please!"
	script.Parent.Touched:Connect(function(Hit)
	if Hit.Parent.Name == hitting then
	Hit.Parent:Destroy()
	NPC.Humanoid:MoveTo(game.Workspace.NPCA.Point4.Position)
		NPC.Humanoid.MoveToFinished:Wait()
		game.Players.LocalPlayer.leaderstats.WorkerPoint.Value = game.Players.LocalPlayer.leaderstats.WorkerPoint.Value + 1
		--removes NPC at end

		script.Parent.Parent:Destroy()
		wait(10)
		local Clone = Online:Clone()
		Clone.Parent = workspace
		wait(5)
	end
end)

This is the script.

Use the Hit to get the player.

1 Like

It is all in the highlighted script in the main photo, I am assuming you can only give points through a Local Script?

How does your game work. Anyplayer can give them the food? Or does each player have an individual store that they give food to the npc? When a player places down the food, you should insert an object value that’s value is the player who placed the food down. Then when the npc hits it, get the player from the object value.

1 Like

Ah, here’s what we can do then: Get the Player Object by using GetPlayerFromCharacter function which will then change the leaderstats to the server-side that way, the only issue I see is the Hit.Parent which I’m assuming is referring to the ChosenFood variable so you may have to do Hit.Parent.Parent instead?

1 Like

Thanks for your help, that’ll work perfectly.

Wait so the food is a child of the player’s character? Is it a tool?

Don’t worry about it I now have a solution, thanks for your interest!

Might wanna confirm doing it first before you mark mine as a real solution, I’m just guessing from know I know here :thinking:

The problem with this is that the “hit” is the food, not the player’s body part.

Oh, I didn’t know that. Maybe try to have a value of the player or their name somewhere like in the NPC where it can get it.