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

Trying to do stuff with leaderstats, but...?

Ok, so... I'm trying to make a system to make that when the player has triggered a prompt, it will add some points to the player and show up in the leaderstats, but... for some reason doesn't work... please help me... I would thank the person who help me with this stuff.

The prompt local script:

local Players = game:GetService("Players")
local player = Players.LocalPlayer

local prompt = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local remotesEvents = replicatedStorage:WaitForChild("RemotesEvents")
local addDevPointsEvent = remotesEvents:WaitForChild("AddDevPoints")

prompt.Triggered:Connect(function()
	addDevPointsEvent:FireServer(player)
end)

And the main server script:

local replicatedStorage = game:GetService("ReplicatedStorage")
local remotesEvents = replicatedStorage:WaitForChild("RemotesEvents")
local addDevPointsEvent = remotesEvents:WaitForChild("AddDevPoints")

local function PlayerSetup(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local devPoints = Instance.new("IntValue", leaderstats)
	devPoints.Name = "DevPoints"
	devPoints.Value = 0
	
	local funds = Instance.new("IntValue", leaderstats)
	funds.Name = "Funds"
	funds.Value = 0
end

game.Players.PlayerAdded:Connect(PlayerSetup)

addDevPointsEvent.OnServerEvent:Connect(function(player)
	player.leaderstats.DevPoints.Value = player.leaderstats.DevPoints.Value + 2
end)

1 answer

Not sure what you're trying to do 100% but, this is something similar. You can modify this to fit your needs.


game.Players.PlayerAdded:Connect(function(plr)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local devPoints = Instance.new("IntValue")
	devPoints.Name = "DevPoints"
	devPoints.Value = 0
	devPoints.Parent = leaderstats
	
	local funds = Instance.new("IntValue")
	funds.Name = "Funds"
	funds.Value = 0
	funds.Parent = leaderstats
end)

script.Parent.ProximityPrompt.Triggered:Connect(function(plr)
	plr:WaitForChild("leaderstats").DevPoints.Value += 2
end)

This is how I have it set up in workspace: https://gyazo.com/705f7421946e9b44acdaf09833e5c840

You can modify how long it takes to activate the prompt in the ProximityPrompt properties.

6 comments

0

I see that you avoided using the second argument of Instance.new. You're correct in setting the Parent property last, but you're missing one extra, vital step: the instance should not be parented until it and its descendants have been configured. You're still deploying the leaderstats folder too early as children still need to be added to it. For leaderstats, it's ultimately best to prefabrica

0

interstng thanks

0

Nop sorry, didn't work

0

can u post the error & and the current script along with your explorer? the script is working for me, we cant help u without any information

0

No errors

0

I'm using a LOCAL SCRIPT inside the prompt, read the local script, I'm using a remote event

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