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 4 years ago

Here is my Server Script

01local Allowed = {'CRAZYQUACKY84'}
02 
03local ReplicatedStorage = game:GetService('ReplicatedStorage')
04local RemoteManager = ReplicatedStorage:WaitForChild('RemoteManager')
05local WarnManager = RemoteManager:WaitForChild('WarningManager')
06 
07game.Players.PlayerAdded:Connect(function(plr)
08    for _,a in pairs(Allowed) do
09        if plr.Name == a then
10            plr.Chatted:Connect(function(warncmnd)
11                if string.sub(warncmnd, 1, 5) == ':warn' then
12                    local plrToWarn = game.Players:FindFirstChild(string.sub(warncmnd, 7))
13                    if plrToWarn then
14                        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')
15                    end
16                end
17            end)
18        end
19    end
20end)

Here is my local script in the UI.

01local ReplicatedStorage = game:GetService('ReplicatedStorage')
02local RemoteManager = ReplicatedStorage:WaitForChild('RemoteManager')
03local WarnManager = RemoteManager:WaitForChild('WarningManager')
04 
05WarnManager.OnClientEvent:Connect(function(msg)
06    wait(1)
07    script.Parent.WarningTitle.Text = msg
08    wait(3)
09    script.Parent.WarningTitle.Text = ''
10end)

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 4 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
4 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:

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

Localscript:

1game.ReplicatedStorage.RemoteEvent.OnClientEvent:connect(function(player)
2    if player.Name == game.Players.LocalPlayer.Name then
3        --function
4    end
5end)

In your case this would be:

Serverscript:

01local Allowed = {'CRAZYQUACKY84'}
02 
03local ReplicatedStorage = game:GetService('ReplicatedStorage')
04local RemoteManager = ReplicatedStorage:WaitForChild('RemoteManager')
05local WarnManager = RemoteManager:WaitForChild('WarningManager')
06 
07game.Players.PlayerAdded:Connect(function(plr)
08    for _,a in pairs(Allowed) do
09        if plr.Name == a then
10            plr.Chatted:Connect(function(warncmnd)
11                if string.sub(warncmnd, 1, 5) == ':warn' then
12                    local plrToWarn = game.Players:FindFirstChild(string.sub(warncmnd, 7))
13                    if plrToWarn then
14                        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)
15                    end
16                end
17            end)
18        end
19    end
20end)

localscript:

01local ReplicatedStorage = game:GetService('ReplicatedStorage')
02local RemoteManager = ReplicatedStorage:WaitForChild('RemoteManager')
03local WarnManager = RemoteManager:WaitForChild('WarningManager')
04 
05WarnManager.OnClientEvent:Connect(function(msg, plrToWarn)
06    if plrToWarn.Name == game.Players.LocalPlayer.Name then -- Not sure if you want it like this but I hope you get the idea.
07    wait(1)
08    script.Parent.WarningTitle.Text = msg
09    wait(3)
10    script.Parent.WarningTitle.Text = ''"
11    end
12end)
0
Thanks bro! CRAZYQUACKY84 113 — 4y

Answer this question