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

Script not adding IntValue or leaderstats???

Asked by
danglt 185
5 years ago
Edited 5 years ago

when i run the game i do not receive the IntValue aka TilesColored and leaderstats do not show up I am very confused about why its not making the IntValue

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("Tiles")



game.Players.PlayerAdded:Connect(function(player)
    local leader = Instance.new("Folder",player)
 leader.Name = "leaderstats"

    local tiles = Instance.new("IntValue",leader)
 tiles.Name = "TilesColored"
 tiles.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, tiles.Value)

    local ye = Instance.new("BrickColorValue",player)
    ye.Name = "colorval"
    ye.Value = BrickColor.Random()

2 answers

Log in to vote
3
Answered by 5 years ago
Edited 5 years ago

The problem lies in the order of your code. Remember that data store save / load requests yield(makes your code pause until it gets a value) meaning that the code will be delayed. The result of this is that the leaderstats are not created as expected.

You should also not be using the parent argument for Instance.new as once you parent it to the game a lot of additional changes are then needed to be replicated to the players. Follow the process, create, setup and parent last. You can parent things to leaderstats and then parent leaderstats to the game.

Lastly your yse of data stores is not safe and can error causing loss of player data. Please check wiki on how to make safe data store calls.

Example

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("Tiles")

game.Player.PlayerAdded:Connect(function(plr)

    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"

    local tiles = Instance.new("IntValue")
    tiles.Name = "TilesColored"
    tiles.Parent = leaderstats

    local ye = Instance.new("BrickColorValue")
    ye.Name = "colorval"
    ye.Value = BrickColor.Random()
    ye.Parent = plr

    leaderstats.Parent = plr

    -- this is not a safe way to use a data store read wiki
    tiles.Value = ds:GetAsync(player.UserId) or 0
end)

Hope this helps.

0
yep thats a pretty big promlem Gey4Jesus69 2705 — 5y
0
still did not fix? danglt 185 — 5y
0
check that there arw no other script causeing this one not to work. This code shoukd work in a blank project. User#5423 17 — 5y
Ad
Log in to vote
-5
Answered by 5 years ago

I LOVE U DUDE AND I WANT TO HELP YOU MAKE THE GAME AS BEST AS IT CAN GET

$$$ Front Page

Make it IntValue and make it called leaderstats DONT SAY IM WRONG BUILDERMAN TAUGHT ME

Answer this question