I have a script that should receive an event, but for some reason the event fires from the local side but it does not receive on the server side. I get no errors or warnings. Please help! Code is down below.
The code (Local side):
SendGUI:FireServer()
The code (Server side):
SendGUI.OnServerEvent:Connect(function(player)
print("The event got fired")
if players:FindFirstChild(player.Name) then
Participants.Value += 1
print("Value should've gotten changed by now: " ..Participants.Value)
local value = Instance.new("NumberValue", workspace.Racetrack1.Players)
value.Name = player.Name
end
end)
--Services
local RS = game:GetService("ReplicatedStorage")
local player = game:GetService("Players").LocalPlayer
--Events
local SendGUI = RS:WaitForChild("Racing"):WaitForChild("SendGUI")
--Items
local debounce = false
local frame = script.Parent
local button = frame.Button
local announcement = frame.Announcement
local decision = frame.Decision
SendGUI.OnClientEvent:Connect(function(show)
if show == 1 then
frame.Visible = true
announcement.Text = "A race is going to start in 30 seconds, would you like to participate?"
announcement.UIStroke.Color = Color3.new(0.0588235, 0.490196, 0)
announcement.Visible = true
button.Visible = true
elseif show == 2 then
frame.Visible = true
announcement.Text = "Not enough players to start a race!"
announcement.UIStroke.Color = Color3.new(0.701961, 0, 0)
announcement.Visible = true
end
end)
button.MouseButton1Click:Connect(function()
if debounce == false then
debounce = true
SendGUI:FireServer(player)
print("The event got fired on the local side")
button.Visible = false
decision.Visible = true
wait(1)
debounce = false
end
end)
Server side:
task.wait(3)
--Services
local players = game:GetService("Players")
local RS = game:GetService("ReplicatedStorage")
--Events
local SendGUI = RS:WaitForChild("Racing"):WaitForChild("SendGUI")
--Items
local Participants = workspace.Racetrack1.Participants
local Ongoing = workspace.Racetrack1.Ongoing
local Racetrack1Parts = workspace.Racetrack1:GetDescendants()
local ToTeleport
for _, part in (Racetrack1Parts) do
if part.Name == "ToTeleport" then
ToTeleport = part
end
end
local StartBarrier = workspace.Racetrack1:WaitForChild("StartBarrier")
local show = 0
while true do
task.wait(20)
Participants.Value = 0
local totalplayers = 0
for i, v in pairs(players:GetChildren()) do
totalplayers += 1
end
if totalplayers >= 1 then
print("Enough players, time to get some speed going over here.")
local show = 1
SendGUI:FireAllClients(show)
task.wait(30)
if Participants.Value >= 1 then
for i, player in pairs(workspace.Racetrack1.Players:GetChildren()) do
if players:FindFirstChild(player) then
print("Participant still exists")
else
Participants.Value =- 1
end
end
if Participants.Value > 1 then
for i, player in pairs(workspace.Racetrack1.Players:GetChildren()) do
players:FindFirstChild(player).Character.HumanoidRootPart.CFrame = ToTeleport.CFrame
end
else
local show = 2
for i, player in pairs(workspace.Racetrack1.Players:GetChildren()) do
if players:FindFirstChild(player) then
SendGUI:FireClient(player)
end
end
end
else
local show = 2
SendGUI:FireAllClients(show)
end
else
print("There weren't enough players")
print("Not enough players as you can see: " ..totalplayers.. ". It's not my fault :(")
end
end
SendGUI.OnServerEvent:Connect(function(player)
print("The event got fired")
if players:FindFirstChild(player.Name) then
Participants.Value += 1
print("Value should've gotten changed by now: " ..Participants.Value)
local value = Instance.new("NumberValue", workspace.Racetrack1.Players)
value.Name = player.Name
end
end)
This would send out SendGUI.OnServerEvent:Connect(function(player, player)
You don’t need to add in the player parameters, because it is already added. You only needed to add the player paramater when using :FireClient(player) so it knows which player to fire to.
Well, that seemed to work, thanks a lot, never expected this to be the issue. It’s one of those scenarios that are really annoying. Thank you once again!