My code just doesnt want to run. I tried using prints to check if it ran that part, but it didn’t.
Full code:
local DadaSer = game:GetService("DataStoreService")
script.Parent.OnServerEvent:Connect(function(plr)
plr.PlayerFolder.Money.Value = math.round(plr.PlayerFolder.Money.Value*0.9)
wait(game.Players.RespawnTime+0.5)
for v, item in game.ReplicatedStorage.SaveToolsList:GetChildren() do
local setval = DadaSer:GetDataStore("Savetool.".. item.Name)
if setval:GetAsync("Savetool.".. item.Name) then
local valuetool = item:Clone()
item.Parent = plr.Backpack
print("Step2")
end
end
end)
Only the code failing:
for v, item in game.ReplicatedStorage.SaveToolsList:GetChildren() do
local setval = DadaSer:GetDataStore("Savetool.".. item.Name)
if setval:GetAsync("Savetool.".. item.Name) then
local valuetool = item:Clone()
item.Parent = plr.Backpack
print("Step2")
end
end
Your data store code is a bit weird, why is the player user id(or any unique identifier related to the player) not included in your data fetching process? I think that your current code allows players to override the data of each other.
try adding in pairs to the loop, but i don’t believe this is the main problem
for v, item in pairs(game.ReplicatedStorage.SaveToolsList:GetChildren()) do
local setval = DadaSer:GetDataStore("Savetool.".. item.Name)
if setval:GetAsync("Savetool.".. item.Name) then
local valuetool = item:Clone()
item.Parent = plr.Backpack
print("Step2")
end
end
i believe the main problem is with the starting line,
script.Parent.OnServerEvent:Connect(function(plr)
this would require a serverscript to be inside a remote event, which is very bad to do, but without an error or something, i can only guess
try defining a remote event, then connecting it to the OnServerEvent function, and then firing the remote event. Then it should run whatever is inside the event
The event fires perfectly, the issue is the loop not running.
script.Parent.Humanoid.Changed:Connect(function()
if script.Parent.Humanoid.Health == 0 or script.Parent.Humanoid.Health < 0 then
game.Workspace.GameFolder.EventsServices.RespawnOn:FireServer()
end
end)
You can write all of the code in the same script, in a server script inside StarterCharacterScripts, if it still does’nt prints be sure that there really is parts in the SaveToolsList folder. Also, it will fire multiple times after you die so be aware of that:
local plr = game.Players:GetPlayerFromCharacter(script.Parent)
local DadaSer = game:GetService("DataStoreService")
local function Update()
plr.PlayerFolder.Money.Value = math.round(plr.PlayerFolder.Money.Value*0.9)
task.wait(game.Players.RespawnTime+0.5)
for v, item in game.ReplicatedStorage.SaveToolsList:GetChildren() do
local setval = DadaSer:GetDataStore("Savetool.".. item.Name)
if setval:GetAsync("Savetool.".. item.Name) then
local valuetool = item:Clone()
item.Parent = plr.Backpack
print("Step2")
end
end
end
script.Parent.Humanoid.Changed:Connect(function()
if script.Parent.Humanoid.Health <= 0 then
Update()
end
end)