Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

[SOLVED] "Unable to cast value to Object" when I'm just trying to fire a client with a RemoteEvent?

Asked by 5 years ago
Edited 5 years ago

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!

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

So, im currently at work but you should try this. Just change these 2 Lines in your script.

(Line 3)

You had it like this

savingGui:FireClient("saving")

But instead, try to do it like this.

Request = saving
savingGui:FireClient(Request)

and for (Line 114),(Line 55) do it like this

Request = save
savingGui:FireClient(Request)

In Localscript:

    local repStorage = game:GetService("ReplicatedStorage")
    local saveGui = repStorage:WaitForChild("Stats-Related"):WaitForChild("SavingGui")

    local saveImage = script.Parent
    local text = saveImage:WaitForChild("TextLabel")



    local openPose = UDim2.new(0.81, 0,0.022, 0)
    local closePose = UDim2.new(1, 0,0.022, 0)

    saveGui.OnClientEvent:Connect(function(Request)
        if Request == "saving" then

            saveImage:TweenPosition(openPose,"Out","Quart",1)


                text.Text = "Saving ."
                wait(1)
                text.Text = "Saving . ."
                wait(1)
                text.Text = "Saving . . ."
                wait(1)


        elseif Request== "saved" then
            wait(1)

            text.Text = "Saved!"
            wait(0.5)
            saveImage:TweenPosition(closePose,"In","Quart",1)
            wait(1)
        end
    end)
0
Mk I'll try it. Knineteen19 307 — 5y
0
I Edit it, try it now. Paintertable 171 — 5y
0
Still shows the same error. Knineteen19 307 — 5y
0
Ah mk. Knineteen19 307 — 5y
View all comments (9 more)
0
Yeah, it just shows the same error. Knineteen19 307 — 5y
0
Wait, I figured it out. Instead of savingGui:FireClient("saving") I needed to include player in it like savingGui:FireClient(player,"saving") Knineteen19 307 — 5y
0
Try it with savingGui:FireClient(player,Request) Paintertable 171 — 5y
0
Thanks anyway though! Knineteen19 307 — 5y
0
Yeah that's what worked for me. Knineteen19 307 — 5y
0
jeah, exacly. Okey, figured it out too :D Nice. I just checked my remote function and it said it there. Paintertable 171 — 5y
0
Would be nice, if you could accept my answer then :)) Paintertable 171 — 5y
0
I'll accept your answer anyway because you helped me figure it out though. Knineteen19 307 — 5y
0
Thanks, good luck with your script Paintertable 171 — 5y
Ad

Answer this question