Leaderstats will only change for the client and not the server

  1. What do you want to achieve? Leaderstats change for all players in the server.

  2. What is the issue? Leaderstats will only change for the client and not the server.

RunContext is Client

local Prompt = game.workspace.ChefHats.Chef1.ChefHat.ProximityPrompt
local player = game.Players.LocalPlayer
Prompt.Triggered:Connect(function(Player)
	local Hats = Player.leaderstats.Hats
	Hats.Value += 1
	workspace.ChefHats.Chef1:WaitForChild('ChefHat'):Destroy()
end)

You’re running this Script on the Client, I’m not sure what to tell you

Just use a Server Script (or RunContext: Server), The first Argument on ProximityPrompt.Triggered is the Player always so its a bit unnessecary.

Replace the local script with a normal server script.
Then use your current script , except delete

He said The Scripts RunContext is Client, Its “not” a LocalScript, but it runs as one

Well then I guess you have the solution.
edit: why is the runcontext client then?

That’s the thing, I’m not sure, ask the OP

if you want to leave hats for other players we recommend remote events

This is me using a Local Script

You should fire a remote to the server and update the value from there

—localscript
local re = game.ReplicatedStorage:FindFirstChild(“Remote Event”)
local Prompt = game.workspace.ChefHats.Chef1.ChefHat.ProximityPrompt
Prompt.Triggered:Connect(function(Player)
	re:FireServer
workspace.ChefHats.Chef1:WaitForChild('ChefHat'):Destroy()
end)

—script
local re = game.ReplicatedStorage:FindFirstChild(“Remote Event”)
re.OnServerEvent:Connect(function(plr)
local hats = plr.leaderstats.Hats
hats.Value += 1
2 Likes

Not sure if I did it right but I put the Local script in the Proximity Prompt and the Script in ServerScriptService and it doesn’t work

1 Like

Use RunContext of server:


local Prompt = game.workspace.ChefHats.Chef1.ChefHat.ProximityPrompt

Prompt.Triggered:Connect(function(Player)
	local Hats = Player.leaderstats.Hats
	Hats.Value += 1
	workspace.ChefHats.Chef1:WaitForChild('ChefHat'):Destroy()
end)
3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.