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

Why is this server message saying the wrong thing? (Remote Events)

Asked by
nanaluk01 247 Moderation Voter
7 years ago
Edited 7 years ago

Why is this server message saying the wrong thing? (Remote Events)

When the server message is created, it says for example:

"[Server]: Nanaluk01 Has Unboxed Nanaluk01" .... why?

And yes, all my variables and values are correct. And no, there is no errors.

This is the part of my code that calls a RemoteEvent that then runs a Server-Script: This is a small part of a script that is a LocalScript

local StartNotification = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("StartNotification")


--//The function that gives the player the item he/she got
function GiveItem(p,Item)
    if Item ~= "150 Coins" and Item ~= "300 Coins" then
        local AwardedItem = ItemsToGiveFolder:FindFirstChild(Item):Clone()
        AwardedItem.Parent = game.Workspace:FindFirstChild(p)
        AwardedItem.Enabled = true

        --//Fire StartNotification(event)
        StartNotification:FireServer(Player,AwardedItem)
    else
        local CoinsToGive = ItemsToGiveFolder:FindFirstChild(Item)
        print("Old Value: " ..Coins.Value)
        Coins.Value = Coins.Value + CoinsToGive.Value
        print("New Value: " ..Coins.Value)

        --//Fire StartNotification(event)
        StartNotification:FireServer(Player.Name,CoinsToGive.Name)
    end
end

Then the RemoteEvent that is called, runs a Server-Script, which has this code: And then the Server-Script fires another event that creates the message in the chat.

local chat_event = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("chat_event") 
local StartNotification = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("StartNotification")

StartNotification.OnServerEvent:connect(function(Player,Name)
    chat_event:FireAllClients("[Server]: " .. Player.Name .. " Has Unboxed " .. Name.Name .. "!")
end)

This is the code for the script that actually creates the message: This is a LocalScript.

local chat_event = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("chat_event")

chat_event.OnClientEvent:connect(function(chat)
    game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage",{Text = chat; color = Color3.new(4,2,0)})
end)

And, I said, it creates a message that says for example this: "[Server]: Nanaluk01 Has Unboxed Nanaluk01" .... which is not what is should say...

It should say something like this, for instance: "[Server]: Nanaluk01 Has Unboxed Sword" ... Why isn't it doing that

1 answer

Log in to vote
1
Answered by
Pyrondon 2089 Game Jam Winner Moderation Voter Community Moderator
7 years ago

The first parameter of any event listener to OnServerEvent is the player which fired the event. You fire the player as an argument expecting it to be the first parameter (Player), when it's really the second (Name). This can be remedied simply by modifying your LocalScript to only fire the event with AwardedItem, omitting Player as it's added automatically, and doing the same for the second one.

local StartNotification = game.ReplicatedStorage:WaitForChild("Events"):WaitForChild("StartNotification")


--//The function that gives the player the item he/she got
function GiveItem(p,Item)
    if Item ~= "150 Coins" and Item ~= "300 Coins" then
        local AwardedItem = ItemsToGiveFolder:FindFirstChild(Item):Clone()
        AwardedItem.Parent = game.Workspace:FindFirstChild(p)
        AwardedItem.Enabled = true

        --//Fire StartNotification(event)
        StartNotification:FireServer(AwardedItem) --// Remove Player here..
    else
        local CoinsToGive = ItemsToGiveFolder:FindFirstChild(Item)
        print("Old Value: " ..Coins.Value)
        Coins.Value = Coins.Value + CoinsToGive.Value
        print("New Value: " ..Coins.Value)

        --//Fire StartNotification(event)
        StartNotification:FireServer(CoinsToGive.Name) --// And here.
    end
end

Hope this helped.

Ad

Answer this question