i dont know what to do can someone explain how to save jumppower if someone leaves the game
Try this maybe:
local d = game:GetService("DataStoreService"):GetDataStore()
game.Players.PlayerAdded:Connect(function(p)
if d:GetAsync(p.userId) ~= nil then
p.Character:WaitForChild("Humanoid").JumpPower = d:GetAsync(p.UserId)[1]
end
end)
game.Players.PlayerRemoving:Connect(function(p)
d:SetAsync(p.UserId,p.Character.Humanoid.JumpPower)
end)
nop
Can you share the output error?
âargument 1 missing or nilâ
local d = game:GetService("DataStoreService"):GetDataStore("JumpPower")
game.Players.PlayerAdded:Connect(function(p)
if d:GetAsync(p.userId) ~= nil then
p.CharacterAdded:Wait()
p.Character:WaitForChild("Humanoid").JumpPower = d:GetAsync(p.UserId)[1]
end
end)
game.Players.PlayerRemoving:Connect(function(p)
d:SetAsync(p.UserId,p.Character.Humanoid.JumpPower)
end)
Is the game published, if its not publish it.
both are in serverscripts and normal scripts
script1:
local d = game:GetService("DataStoreService"):GetDataStore("JumpPower")
game.Players.PlayerAdded:Connect(function(p)
if d:GetAsync(p.userId) ~= nil then
p.CharacterAdded:Wait()
p.Character:WaitForChild("Humanoid").JumpPower = d:GetAsync(p.UserId)[1]
end
end)
game.Players.PlayerRemoving:Connect(function(p)
d:SetAsync(p.UserId,p.Character.Humanoid.JumpPower)
end)
script2:
game.Players.PlayerAdded:Connect(function(plr)
wait(5)
while wait(1) do
plr.Character.Humanoid.JumpPower = plr.Character.Humanoid.JumpPower + 10
end
end)
api enables is on
Okay, but is the game published?
yes it is
Hm, sadly im not sure in that case.
Remove the [1] after the d:GetAsync(p.UserId). Youâre not saving a table to the datastore so the key will simply reference to the ONE thing you have saved.
Also, try to use more meaningful variable names to improve the readability of your code. Instead of âpâ, use âplrâ or âplayerâ - try to avoid meaningless single letter variables.
still not working
script:
local d = game:GetService("DataStoreService"):GetDataStore("JumpPower")
game.Players.PlayerAdded:Connect(function(plr)
if d:GetAsync(plr.userId) ~= nil then
plr.CharacterAdded:Wait()
plr.Character.Humanoid.JumpPower = d:GetAsync(plr.UserId)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
d:SetAsync(plr.UserId,plr.Character.Humanoid.JumpPower)
end)
ServerScriptService.Script:6: attempt to index nil with âHumanoidâ
Assuming this is coming from the script you posted, youâre going to want to add back the :WaitForChild("Humanoid") on the effected line. Let me know if this works out for you.
local jumpDatastore = game:GetService("DataStoreService"):GetDataStore("JumpPower")
game.Players.PlayerAdded:Connect(function(plr)
if jumpDatastore:GetAsync(plr.userId) ~= nil then
plr.CharacterAdded:Wait()
plr.Character:WaitForChild("Humanoid").JumpPower = jumpDatastore:GetAsync(plr.UserId)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
jumpDatastore:SetAsync(plr.UserId,plr.Character.Humanoid.JumpPower)
end)
However, it looks like the error ServerScriptService.Script:6: attempt to index nil with âHumanoidâ is coming from the script youâre using to edit the JumpPower of a player every second that you posted earlier. Try the following instead:
game.Players.PlayerAdded:Connect(function(plr)
wait(5)
while wait(1) do
if plr.Character.Humanoid then
plr.Character.Humanoid.JumpPower = plr.Character.Humanoid.JumpPower + 10
end
end
end)
Personally Iâd recommend changing a few things for best practice sake (I just copy and pasted your original script and made changes), but overall this should accomplish what youâre trying to do.
local ds = game:GetService("DataStoreService"):GetDataStore("JumpPower")
game.Players.PlayerAdded:Connect(function(plr)
local data = ds:GetAsync(plr.userId)
plr.CharacterAdded:Connect(function(char)
if data then
if char.Parent ~= workspace then char.AncestryChanged:Wait() end
char:WaitForChild("Humanoid").JumpPower = data
end
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
ds:SetAsync(plr.UserId,plr.Character.Humanoid.JumpPower)
end)