#Remote event "Unable to cast value to object"

1 messages · Page 1 of 1 (latest)

lofty carbon
#

I am making a broadcasting system for a game but my script is giving my this error, I have gotten it before but i still do not know how to fix it.

module.Broadcast = function(Text,Player)
    for i,v in game.Players:GetChildren() do
        if v.Name == Player then
            v.PlayerGui.BroadcastGui.Main.TextLabel.Broadcast:FireClient(Player,Text)
        end
    end
end

local script pov:

script.Parent.OnClientEvent:Connect(function(Player,Text)
    if Text ~= string then return end
    script.Parent.Parent.Parent.Parent.Enabled = true
    script.Parent.Parent.Text = Text
    task.wait(2)
    script.Parent.Parent.Parent.Parent.Enabled = false
    script.Parent.Parent.Text = "Message"
end)
ripe iron
lofty carbon
#

oh right

#

Remote event "Unable to cast value to object" solvedg

#

Remote event "Unable to cast value to object"

ripe iron
lofty carbon
#

it is the same error

ripe iron
# lofty carbon it is the same error

Because you're giving Player, which looks like the player's name, but v is the player instance. You need to use the player instance with FireClient

lofty carbon
#

after the local script gets the text is is nil but not on anywhere else it has text??

ripe iron
lofty carbon
ripe iron
lofty carbon
ripe iron
lofty carbon
#

ok so the remote event is returning text as nil when it is receving the first 2 things that printed

string is a thing roblox has that you can use to find a string like i did there but its not a string so it wont work.

ripe iron
lofty carbon
#

no

#

the thing i use is the same

ripe iron
lofty carbon
#

ok

#

it does but also even if i did not have it at start it would still be nil

lofty carbon
#

updated script

script.Parent.OnClientEvent:Connect(function(Player,Text)
    if Text ~= string then print("No text! Continuing script.") end
    script.Parent.Parent.Parent.Parent.Enabled = true
    script.Parent.Parent.Text = tostring(Text)
    print(Text)
    task.wait(1.5)
    script.Parent.Parent.Parent.Parent.Enabled = false
    script.Parent.Parent.Text = "Message"
end)
#

textlabel gets set to nil now

ripe iron
#

OnClientEvent does not give the Player parameter.

The player argument is only used by FireClient

lofty carbon
#

huhh

#

why remote events be so annoying 😭🙏

ripe iron
lofty carbon
ripe iron
lofty carbon
#

wait

#

i tihnk its fixed

#

it works now!

ripe iron
#

yay