I wanted to make my Boat data and leveling up data work but because they have the same name they dont seem to work
They are both scripts in Serverscriptservice
I tried changing their names so both of them works instead of only one
but it didnt work the one I changed the name is the one who didnt work, I didnt just change the script name I also change the name on the script
can anyone help me with this so both the boat and the stats work together
make whatever script that is trying to get the values do WaitForChild("Data"):WaitForChild("BoatOwned")
If its a local script, i heavily recommend that you have the LocalScript wait for the characters humanoid, this usually ensures that the player is fully loaded into the game.
repeat
wait()
until game.Players.LocalPlayer.Character and game.Players.LocalPlayer.Character:FindFirstChild("Humanoid")
If both of those solutions dont work, attempt forcing the data to load upon a RemoteFunction.
Why a RemoteFunction and not an RemoteEvent, you may ask.
Well, calling a RemoteFunction will cause a LocalScript to wait for a response from the server.
You can easily make the data load from the server from the function, and then make the server return true or "data loaded!".
Also, for easier script management, i would recommend putting all DataStore scripts into a single script, instead of having one script for one datastore, and another script for a different datastore.
game.Players.PlayerAdded:Connect(function(Plr)
local stats = Instance.new(“Folder”, Plr)
stats.Name = “Data”
— Level System
local Levels = Instance.new(“IntValue”, stats)
Levels.Name = “Levels”
Levels.Value = 1
local Exp = Instance.new(“IntValue”, stats)
Exp.Name = “Exp”
Exp.Value = 0
local ExpNeed = Instance.new(“IntValue”, stats)
ExpNeed.Name = “ExpNeed”
ExpNeed.Value = 200
— Money System
local Beli = Instance.new(“IntValue”, stats)
Beli.Name = “Beli”
Beli.Value = 10000
local Bounty = Instance.new(“IntValue”, stats)
Bounty.Name = “Bounty”
Bounty.Value = 0
— Stats Text
local HealthP = Instance.new(“IntValue”, stats)
HealthP.Name = “HealthP”
HealthP.Value = 0
local MeleeP = Instance.new(“IntValue”, stats)
MeleeP.Name = “MeleeP”
MeleeP.Value = 0
local SpeedP = Instance.new(“IntValue”, stats)
SpeedP.Name = “SwordP”
SpeedP.Value = 0
local DevilFruitP = Instance.new(“IntValue”, stats)
DevilFruitP.Name = “DevilFruitP”
DevilFruitP.Value = 0
— Stats System
local Points = Instance.new(“IntValue”, stats)
Points.Name = “Points”
Points.Value = 0
local MaxHealth = Instance.new(“IntValue”, stats)
MaxHealth.Name = “MaxHealth”
MaxHealth.Value = 0
local Melee = Instance.new(“IntValue”, stats)
Melee.Name = “Melee”
Melee.Value = 0
local Speed = Instance.new(“NumberValue”, stats)
Speed.Name = “Sword”
Speed.Value = 0
— Sword
local Sword = Instance.new(“StringValue”, stats)
Sword.Name = “SwordOwned”
Sword.Value = “None”
— Melee
local Melee = Instance.new(“StringValue”, stats)
Melee.Name = “MeleeOwned”
Melee.Value = “Combat”
end)
game.Players.PlayerAdded:Connect(function(Plr)
local stats = Instance.new(“Folder”, Plr)
stats.Name = “BoatOwned”
— Current Boat
local BoatOwned = Instance.new(“StringValue”, stats) —The boat script here
BoatOwned.Name = “BoatOwned”
BoatOwned.Value = “SailBoat”
WaitForChild("Data"):WaitForChild("BoatOwned")
end)
game.Players.PlayerAdded:Connect(function(plr)
wait(.1)
local Exp = plr.Data.Exp
local Levels = plr.Data.Levels
local ExpNeed = plr.Data.ExpNeed
local Points = plr.Data.Points
while wait() do
if Exp.Value >= (100 * (Levels.Value + 1)) and Levels.Value <= 399 then
Levels.Value = Levels.Value + 1
Points.Value = Points.Value + 3
Exp.Value = Exp.Value - ExpNeed.Value
ExpNeed.Value = ExpNeed.Value + 100
game.ReplicatedStorage.LevelSystem.LevelUpGui:FireClient(plr)
end
end
end)
There
At this state the Money system works and everything except for what I needed the boat which is separated before with the same name called “Data” in a script in serverscriptservice
I added EZQP3’s suggestion to ad waitforchild but I dont think I’ve done it right
game.Players.PlayerAdded:Connect(function(Plr)
local stats = Instance.new(“Folder”, Plr)
stats.Name = “BoatOwned”
— Current Boat
local BoatOwned = Instance.new(“StringValue”, stats)
BoatOwned.Name = “BoatOwned”
BoatOwned.Value = “SailBoat”
stats.Name = "Data"
--- Level System
local Levels = Instance.new("IntValue", stats)
Levels.Name = "Levels"
Levels.Value = 1
local Exp = Instance.new("IntValue", stats)
Exp.Name = "Exp"
Exp.Value = 0
local ExpNeed = Instance.new("IntValue", stats)
ExpNeed.Name = "ExpNeed"
ExpNeed.Value = 1000
--- Money System
local Beli = Instance.new("IntValue", stats)
Beli.Name = "Beli"
Beli.Value = 10
local Bounty = Instance.new("IntValue", stats)
Bounty.Name = "Bounty"
Bounty.Value = 0
--- Stats Text
local HealthP = Instance.new("IntValue", stats)
HealthP.Name = "HealthP"
HealthP.Value = 0
local MeleeP = Instance.new("IntValue", stats)
MeleeP.Name = "MeleeP"
MeleeP.Value = 0
local SpeedP = Instance.new("IntValue", stats)
SpeedP.Name = "SwordP"
SpeedP.Value = 0
local DevilFruitP = Instance.new("IntValue", stats)
DevilFruitP.Name = "DevilFruitP"
DevilFruitP.Value = 0
--- Stats System
local Points = Instance.new("IntValue", stats)
Points.Name = "Points"
Points.Value = 0
local MaxHealth = Instance.new("IntValue", stats)
MaxHealth.Name = "MaxHealth"
MaxHealth.Value = 0
local Melee = Instance.new("IntValue", stats)
Melee.Name = "Melee"
Melee.Value = 0
local Speed = Instance.new("NumberValue", stats)
Speed.Name = "Sword"
Speed.Value = 0
--- Sword
local Sword = Instance.new("StringValue", stats)
Sword.Name = "SwordOwned"
Sword.Value = "None"
--- Melee
local Melee = Instance.new("StringValue", stats)
Melee.Name = "MeleeOwned"
Melee.Value = "Combat"
end)
game.Players.PlayerAdded:Connect(function(plr)
wait(.1)
local Exp = plr.Data.Exp
local Levels = plr.Data.Levels
local ExpNeed = plr.Data.ExpNeed
local Points = plr.Data.Points
while wait() do
if Exp.Value >= (100 * (Levels.Value + 1)) and Levels.Value <= 399 then
Levels.Value = Levels.Value + 1
Points.Value = Points.Value + 3
Exp.Value = Exp.Value - ExpNeed.Value
ExpNeed.Value = ExpNeed.Value + 100
game.ReplicatedStorage.LevelSystem.LevelUpGui:FireClient(plr)
end
end