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

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

Asked by 11 months ago

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

Log in to vote
0
Answered by 11 months ago
Edited 11 months ago

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.

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 Ziffixture 6913 — 11mo
0
interstng thanks MaleficentMaestro 109 — 11mo
0
Nop sorry, didn't work Hgamerpro50 0 — 11mo
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 MaleficentMaestro 109 — 11mo
View all comments (2 more)
0
No errors Hgamerpro50 0 — 11mo
0
I'm using a LOCAL SCRIPT inside the prompt, read the local script, I'm using a remote event Hgamerpro50 0 — 11mo
Ad

Answer this question