You can write your topic however you want, but you need to answer these questions:
My Server Script is loading long before local scripts…
- What is the issue? Include screenshots / videos if possible!
Building a Test Shop System and the players Values populate sometimes and other times the data does not populate and leaves the default text in the placeholder.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I added a wait(10) in order to make sure it fully populates and it works fine, but this seems a bit crazy.
with a wait(1) the stone value would populate but not the iron value. Using many print statements I found it has something to do with the time it takes to load the local script for the iron value.
Thoughts? Also only been scripting for 2 months or so… so be nice Thank you for your help!
SERVER SCRIPT:
serverStorage = game:GetService("ServerStorage")
replicatedStorage = game:GetService("ReplicatedStorage")
Players = game:GetService("Players")
local Remotes = replicatedStorage:WaitForChild("Remotes")
local BuyEvent = Remotes:FindFirstChild("Buy")
local UpdateValue = Remotes:FindFirstChild("UpdateValue")
local stoneValue = 100
local stoneNum = 1
local ironValue = 200
local ironNum = 1
Players.PlayerAdded:Connect(function(player)
local PlayerFolder = serverStorage:WaitForChild(player.Name)
local goldCoins = PlayerFolder:FindFirstChild("GoldCoins")
local stone = PlayerFolder:FindFirstChild("Stone")
local iron = PlayerFolder:FindFirstChild("Iron")
**wait(10)**
** **
** UpdateValue:FireClient(player, stone.Value, iron.Value)**
BuyEvent.OnServerEvent:Connect(function(player, itemName, Quantity1, Quantity2, Quantity3)
if itemName == "Stone" then
if Quantity1 == 1 then
if goldCoins.Value >= stoneValue * Quantity1 then
goldCoins.Value = goldCoins.Value - stoneValue * Quantity1
stone.Value = stone.Value + Quantity1
UpdateValue:FireClient(player, stone.Value, iron.Value)
print("BOUGHT 1 STONE")
else
print("NOT ENOUGH GOLD COINS")
end
elseif
Quantity2 == 10 then
if goldCoins.Value >= stoneValue * Quantity2 then
goldCoins.Value = goldCoins.Value - stoneValue * Quantity2
stone.Value = stone.Value + Quantity2
UpdateValue:FireClient(player, stone.Value, iron.Value)
print("BOUGHT 10 STONE")
else
print("NOT ENOUGHT GOLD COINS")
end
elseif
Quantity3 == 100 then
if goldCoins.Value >= stoneValue * Quantity3 then
goldCoins.Value = goldCoins.Value - stoneValue * Quantity3
stone.Value = stone.Value + Quantity3
UpdateValue:FireClient(player, stone.Value, iron.Value)
print("BOUGHT 100 STONE")
else
print("NOT ENOUGH GOLD COINS")
end
end
elseif
itemName == "Iron" then
if Quantity1 == 1 then
if goldCoins.Value >= ironValue * Quantity1 then
goldCoins.Value = goldCoins.Value - ironValue * Quantity1
iron.Value = iron.Value + Quantity1
UpdateValue:FireClient(player, stone.Value, iron.Value)
print("BOUGHT 1 IRON")
else
print("NOT ENOUGH GOLD COINS")
end
elseif
Quantity2 == 10 then
if goldCoins.Value >= ironValue * Quantity2 then
goldCoins.Value = goldCoins.Value - ironValue * Quantity2
iron.Value = iron.Value + Quantity2
UpdateValue:FireClient(player, stone.Value, iron.Value)
print("BOUGHT 10 IRON")
else
print("NOT ENOUGHT GOLD COINS")
end
elseif
Quantity3 == 100 then
if goldCoins.Value >= ironValue * Quantity3 then
goldCoins.Value = goldCoins.Value - ironValue * Quantity3
iron.Value = iron.Value + Quantity3
UpdateValue:FireClient(player, stone.Value, iron.Value)
print("BOUGHT 100 IRON")
else
print("NOT ENOUGH GOLD COINS")
end
end
end
end)
end)
LOCAL SCRIPT LISTENING FOR REMOTE:
replicatedStorage = game:GetService("ReplicatedStorage")
local Remotes = replicatedStorage:WaitForChild("Remotes")
local UpdateValue = Remotes:FindFirstChild("UpdateValue")
print(UpdateValue.Name.. "FOUND")
local function updateValues(stone, iron)
local Quantity = script.Parent
print("FIRED")
Quantity.Text = ""..iron
end
UpdateValue.OnClientEvent:Connect(updateValues)