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

I have problems with "unable to cast value to object". What to do?

Asked by 6 years ago
Edited 6 years ago

Hi i had a question because this is the first time i'm using FireClient/FireServer and RemoteEvents.

From what i know FireServer can only be used with a localscript and FireClient can be used on a script (Correct me if i'm wrong).

So i wanted to make a RemoteEvent when i rank up(when the rank value changes) that there will be some Fireworks! But it won't work on the line with:

rank.Changed:connect(function()
    onRankChanged(plr)
end)

everytime it says "unable to cast value to object" and i can't fix it so if you can please say what i need to do :) and what i did wrong!

Thanks! (P.S. I won't give that much of the code because it's something i don't realy want to sare if you know what i mean :P)

--Script

rank.Changed:connect(function()
    onRankChanged(plr)
end)

function onRankChanged(plr)
    local leaderstats = game.Players:FindFirstChild(plr.Name):findFirstChild("leaderstats")
    if (leaderstats ~= nil) then
        local rank = leaderstats:FindFirstChild("Rank")
        if plr ~= nil then
            if game.Players:FindFirstChild(plr.Name) ~= nil then
                if (rank ~= nil) and (leaderstats ~= nil) then
                    rEvents:FindFirstChild("FireworkEvent"):FireClient(game.Players:FindFirstChild(plr.Name),"Rank Up!")
                end
            end
        end
    end
end
--LocalScript

local FWEvent = game.ReplicatedStorage.Events.FireworkEvent

FWEvent.OnClientEvent:connect(function()
    Fireworks(12)
end)
0
What line does the error appear on? UgOsMiLy 1074 — 6y
0
on line 4 in the "Script" rennoc100 -4 — 6y
0
That means that the error probably appears in the function. Is that the entire error output? UgOsMiLy 1074 — 6y
0
yes rennoc100 -4 — 6y
View all comments (2 more)
0
That error normally appears when you call a function with the wrong type of argument. What type of value is "plr"? UgOsMiLy 1074 — 6y
0
"plr" is a value from a PlayerAdded function andline4 is in that function because of leaderboard rennoc100 -4 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
rank.Changed:connect(function(plr) -- You need to set player as a received argument.
    onRankChanged(plr)
end)
0
The only paramater for "Changed" is the property that was changed. "plr" is in no way a reference to the local player object. Gey4Jesus69 2705 — 6y
Ad

Answer this question