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

Unable to cast value to Object - Why is this?

Asked by 3 years ago

Here is my Server Script

local Allowed = {'CRAZYQUACKY84'}

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RemoteManager = ReplicatedStorage:WaitForChild('RemoteManager')
local WarnManager = RemoteManager:WaitForChild('WarningManager')

game.Players.PlayerAdded:Connect(function(plr)
    for _,a in pairs(Allowed) do
        if plr.Name == a then
            plr.Chatted:Connect(function(warncmnd)
                if string.sub(warncmnd, 1, 5) == ':warn' then
                    local plrToWarn = game.Players:FindFirstChild(string.sub(warncmnd, 7))
                    if plrToWarn then
                        WarnManager:FireClient('You have been given a warning by: '..plr.Name..'\n Reason: Violating Terms of Service, if commited again will lead to a kick')
                    end
                end
            end)
        end
    end
end)

Here is my local script in the UI.

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RemoteManager = ReplicatedStorage:WaitForChild('RemoteManager')
local WarnManager = RemoteManager:WaitForChild('WarningManager')

WarnManager.OnClientEvent:Connect(function(msg)
    wait(1)
    script.Parent.WarningTitle.Text = msg
    wait(3)
    script.Parent.WarningTitle.Text = ''
end)

I am trying to get it to write a command to send a UI message to a specific player.

2 answers

Log in to vote
0
Answered by 3 years ago

The remote "WarnManager" is a remote event, so it takes a player object as its first argument.

You only did :FireClient with a string as an argument, you forgot to include the player being warned (plrToWarn) as the first argument.

Ad
Log in to vote
0
Answered by
rabbi99 714 Moderation Voter
3 years ago

:FireClient() Does not exist. Instead you need to do :FireAllClients(). If you want to send it to a specific player you need to do this for example:

Serverscript:

game.Players.PlayerAdded:connect(function(player)
    game.ReplicatedStorage.RemoteEvent:FireAllClients(player)
end)

Localscript:

game.ReplicatedStorage.RemoteEvent.OnClientEvent:connect(function(player)
    if player.Name == game.Players.LocalPlayer.Name then
        --function
    end
end)

In your case this would be:

Serverscript:

local Allowed = {'CRAZYQUACKY84'}

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RemoteManager = ReplicatedStorage:WaitForChild('RemoteManager')
local WarnManager = RemoteManager:WaitForChild('WarningManager')

game.Players.PlayerAdded:Connect(function(plr)
    for _,a in pairs(Allowed) do
        if plr.Name == a then
            plr.Chatted:Connect(function(warncmnd)
                if string.sub(warncmnd, 1, 5) == ':warn' then
                    local plrToWarn = game.Players:FindFirstChild(string.sub(warncmnd, 7))
                    if plrToWarn then
                        WarnManager:FireAllClients('You have been given a warning by: '..plr.Name..'\n Reason: Violating Terms of Service, if commited again will lead to a kick', plr, plrToWarn)
                    end
                end
            end)
        end
    end
end)

localscript:

local ReplicatedStorage = game:GetService('ReplicatedStorage')
local RemoteManager = ReplicatedStorage:WaitForChild('RemoteManager')
local WarnManager = RemoteManager:WaitForChild('WarningManager')

WarnManager.OnClientEvent:Connect(function(msg, plrToWarn)
    if plrToWarn.Name == game.Players.LocalPlayer.Name then -- Not sure if you want it like this but I hope you get the idea.
    wait(1)
    script.Parent.WarningTitle.Text = msg
    wait(3)
    script.Parent.WarningTitle.Text = ''"
    end
end)
0
Thanks bro! CRAZYQUACKY84 113 — 3y

Answer this question