So I'm trying to make so whenever the stats save in my game with DataStore, it fires a client to pop up a GUI that shows that it's autosaving. Whenever I run the game, it pops with the error of "Unable to cast value to Object" which makes no sense to me because it has nothing to do with a value or an object. I'm a little new to RemoteEvents still, but I mainly am still trying to figure out how Server to Client works and all.
Server:
-- Had to cut the script short. It wouldn't let me post the question otherwise cause it was over 10,000 characters.
while wait(20) do
savingGui:FireClient("saving") -- This is where it says the problem is.
if limitBreaker.Value ~= true then
print("Saving "..player.Name.."'s Data . . .")
if limitBreaker.Value ~= true then
slds:SetAsync(player.UserId,player.Stats.Strength.StrengthLevel.Value)
sxpds:SetAsync(player.UserId,player.Stats.Strength.StrengthXp.Value)
end
if limitBreaker.Value ~= true then
jlds:SetAsync(player.UserId,player.Stats.Jump.JumpLevel.Value)
jxpds:SetAsync(player.UserId,player.Stats.Jump.JumpXp.Value)
end
if limitBreaker.Value ~= true then
alds:SetAsync(player.UserId,player.Stats.Agility.AgilityLevel.Value)
axpds:SetAsync(player.UserId,player.Stats.Agility.AgilXp.Value)
end
if limitBreaker.Value ~= true then
plds:SetAsync(player.UserId,player.Stats.Power.PowerLevel.Value)
pxpds:SetAsync(player.UserId,player.Stats.Power.PowerXp.Value)
end
powerStore:SetAsync(player.UserId,player.leaderstats.Power.Value)
print("Saved "..player.Name.."'s data of "..slds:GetAsync(player.UserId).." strength, "..jlds:GetAsync(player.UserId).." jump, "..plds:GetAsync(player.UserId).." power, and "..alds:GetAsync(player.UserId).." agility!")
elseif limitBreaker.Value == true then
print("Saving "..player.Name.."'s Data . . .")
if limitBreaker.Value == true then
slds:SetAsync(player.UserId,player.Stats.Strength.StrengthLevel.Value/2)
sxpds:SetAsync(player.UserId,player.Stats.Strength.StrengthXp.Value)
end
if limitBreaker.Value == true then
jlds:SetAsync(player.UserId,player.Stats.Jump.JumpLevel.Value/2)
jxpds:SetAsync(player.UserId,player.Stats.Jump.JumpXp.Value)
end
if limitBreaker.Value == true then
alds:SetAsync(player.UserId,player.Stats.Agility.AgilityLevel.Value/2)
axpds:SetAsync(player.UserId,player.Stats.Agility.AgilXp.Value)
end
if limitBreaker.Value ~= true then
plds:SetAsync(player.UserId,player.Stats.Power.PowerLevel.Value/2)
pxpds:SetAsync(player.UserId,player.Stats.Power.PowerXp.Value)
end
powerStore:SetAsync(player.UserId,player.leaderstats.Power.Value)
print("Saved "..player.Name.."'s data of "..slds:GetAsync(player.UserId).." strength, "..jlds:GetAsync(player.UserId).." jump, "..plds:GetAsync(player.UserId).." power, and "..alds:GetAsync(player.UserId).." agility!")
end
savingGui:FireClient("saved")
end
end)
end)
game.Players.PlayerRemoving:connect(function(player)
local limitBreaker = game.Workspace:WaitForChild(player.Name).Skills.LocalLimitBreaker:WaitForChild("LimitBreaker")
savingGui:FireClient("saving")
if limitBreaker.Value ~= true then
print("Saving "..player.Name.."'s Data . . .")
if limitBreaker.Value ~= true then
slds:SetAsync(player.UserId,player.Stats.Strength.StrengthLevel.Value)
sxpds:SetAsync(player.UserId,player.Stats.Strength.StrengthXp.Value)
end
if limitBreaker.Value ~= true then
jlds:SetAsync(player.UserId,player.Stats.Jump.JumpLevel.Value)
jxpds:SetAsync(player.UserId,player.Stats.Jump.JumpXp.Value)
end
if limitBreaker.Value ~= true then
alds:SetAsync(player.UserId,player.Stats.Agility.AgilityLevel.Value)
axpds:SetAsync(player.UserId,player.Stats.Agility.AgilXp.Value)
end
if limitBreaker.Value ~= true then
plds:SetAsync(player.UserId,player.Stats.Power.PowerLevel.Value)
pxpds:SetAsync(player.UserId,player.Stats.Power.PowerXp.Value)
end
powerStore:SetAsync(player.UserId,player.leaderstats.Power.Value)
print("Saved "..player.Name.."'s data of "..slds:GetAsync(player.UserId).." strength, "..jlds:GetAsync(player.UserId).." jump, "..plds:GetAsync(player.UserId).." power, and "..alds:GetAsync(player.UserId).." agility!")
elseif limitBreaker.Value == true then
print("Saving "..player.Name.."'s Data . . .")
if limitBreaker.Value == true then
slds:SetAsync(player.UserId,player.Stats.Strength.StrengthLevel.Value/2)
sxpds:SetAsync(player.UserId,player.Stats.Strength.StrengthXp.Value)
end
if limitBreaker.Value == true then
jlds:SetAsync(player.UserId,player.Stats.Jump.JumpLevel.Value/2)
jxpds:SetAsync(player.UserId,player.Stats.Jump.JumpXp.Value)
end
if limitBreaker.Value == true then
alds:SetAsync(player.UserId,player.Stats.Agility.AgilityLevel.Value/2)
axpds:SetAsync(player.UserId,player.Stats.Agility.AgilXp.Value)
end
if limitBreaker.Value ~= true then
plds:SetAsync(player.UserId,player.Stats.Power.PowerLevel.Value/2)
pxpds:SetAsync(player.UserId,player.Stats.Power.PowerXp.Value)
end
powerStore:SetAsync(player.UserId,player.leaderstats.Power.Value)
print("Saved "..player.Name.."'s data of "..slds:GetAsync(player.UserId).." strength, "..jlds:GetAsync(player.UserId).." jump, "..plds:GetAsync(player.UserId).." power, and "..alds:GetAsync(player.UserId).." agility!")
end
savingGui:FireClient("saved")
end)
Client:
local repStorage = game:GetService("ReplicatedStorage")
local saveGui = repStorage:WaitForChild("Stats-Related"):WaitForChild("SavingGui")
local saveImage = script.Parent
local text = saveImage:WaitForChild("TextLabel")
local enabled = false
local openPose = UDim2.new(0.81, 0,0.022, 0)
local closePose = UDim2.new(1, 0,0.022, 0)
saveGui.OnClientEvent:Connect(function(stateOfSaving)
if stateOfSaving == "saving" then
enabled = true
saveImage:TweenPosition(openPose,"Out","Quart",1)
while enabled == true do -- To be honest, I don't think this is going to stop when the RemoteEvent is going to be fired, so help with how else to make this stop is also appreciated.
text.Text = "Saving ."
wait(1)
text.Text = "Saving . ."
wait(1)
text.Text = "Saving . . ."
wait(1)
end
elseif stateOfSaving == "saved" then
wait(1)
enabled = false
text.Text = "Saved!"
wait(0.5)
saveImage:TweenPosition(closePose,"In","Quart",1)
wait(1)
end
end)
Sorry for the long server script, but just look at the comments to find where it says the problem is. Any help is appreciated though!

13 comments
Mk I'll try it.
I Edit it, try it now.
Still shows the same error.
Ah mk.
Yeah, it just shows the same error.
Wait, I figured it out. Instead of savingGui:FireClient("saving") I needed to include player in it like savingGui:FireClient(player,"saving")
Try it with savingGui:FireClient(player,Request)
Thanks anyway though!
Yeah that's what worked for me.
jeah, exacly. Okey, figured it out too :D Nice. I just checked my remote function and it said it there.
Would be nice, if you could accept my answer then :))
I'll accept your answer anyway because you helped me figure it out though.
Thanks, good luck with your script