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

Leaderstat is showing in Roblox Studio, but not in Roblox itself?

Asked by 1 year ago
Edited 1 year ago

Ok, for some reason my leaderstat will appear when I test the game in roblox studio, but when I launch the game on Roblox itself it just isnt there. Every person who joins the game has the same issue.

My code to create the leaderstat is:

local Players = game:GetService("Players")

local function abilty(player)
    local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

    local abilitychoice = Instance.new("StringValue")
    abilitychoice.Name = "Ability"
    abilitychoice.Value = ""
    abilitychoice.Parent = leaderstats
end

Players.PlayerAdded:Connect(abilty)

local InfernoRemote = game.ReplicatedStorage.InfernoRemote -- find remote
local BiohazardRemote = game.ReplicatedStorage.BiohazardRemote -- find remote
local IllusionRemote = game.ReplicatedStorage.IllusionRemote -- find remote
local ArcticRemote = game.ReplicatedStorage.ArcticRemote -- find remote
local LightningRemote = game.ReplicatedStorage.LightningRemote -- find remote
local SpikeRemote = game.ReplicatedStorage.SpikeRemote -- find remote
local UppercutRemote = game.ReplicatedStorage.UppercutRemote -- find remote
local plr = game.Players.LocalPlayer -- find player to use in normal script


InfernoRemote.OnServerEvent:Connect(function(plr) -- when remote fired this will start i also passed trough plr so we can use that
    plr.leaderstats.Ability.Value = "Inferno" -- this is a example of a value but yeh im adding +1
end)


BiohazardRemote.OnServerEvent:Connect(function(plr) -- when remote fired this will start i also passed trough plr so we can use that
    plr.leaderstats.Ability.Value = "Biohazard" -- this is a example of a value but yeh im adding +1
end)


IllusionRemote.OnServerEvent:Connect(function(plr) -- when remote fired this will start i also passed trough plr so we can use that
    plr.leaderstats.Ability.Value = "Illusion" -- this is a example of a value but yeh im adding +1
end)


ArcticRemote.OnServerEvent:Connect(function(plr) -- when remote fired this will start i also passed trough plr so we can use that
    plr.leaderstats.Ability.Value = "Arctic" -- this is a example of a value but yeh im adding +1
end)


LightningRemote.OnServerEvent:Connect(function(plr) -- when remote fired this will start i also passed trough plr so we can use that
    plr.leaderstats.Ability.Value = "Lightning" -- this is a example of a value but yeh im adding +1
end)


SpikeRemote.OnServerEvent:Connect(function(plr) -- when remote fired this will start i also passed trough plr so we can use that
    plr.leaderstats.Ability.Value = "Spike" -- this is a example of a value but yeh im adding +1
end)


UppercutRemote.OnServerEvent:Connect(function(plr) -- when remote fired this will start i also passed trough plr so we can use that
    plr.leaderstats.Ability.Value = "Uppercut" -- this is a example of a value but yeh im adding +1
end)

and my code to give the leaderstat is

-- local script
local remote = game.ReplicatedStorage.IllusionRemote-- find remote
local plr = game.Players.LocalPlayer -- find player to use in normal script
local gui = script.Parent -- put local script in the gui u wanna click
gui.MouseButton1Click:Connect(function()-- setting clicking function
    remote:FireServer() -- firing remote
end)

(its the same for all abilities just with different remotes) it wasn't happening an hour ago, I haven't even edited anything it just stopped working

1 answer

Log in to vote
0
Answered by 1 year ago

I feel like you should put the leaderstats OUTSIDE of your function, because as of right now you're just creating a bunch of leaderstat folders. (no idea if this will work, just attemting to solve your problem.)

local Players = game:GetService("Players")
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local function abilty(player)
    local abilitychoice = Instance.new("StringValue")

    abilitychoice.Name = "Ability"
    abilitychoice.Value = ""
    abilitychoice.Parent = leaderstats
end

Players.PlayerAdded:Connect(abilty)

--the rest of your code here
0
That wouldn't work because 'player' is not defined before line 4. boredlake 256 — 1y
Ad

Answer this question