Hello, I’m making a game and wanted to make it so that when you click a button something happens. I’m using events to do this where when you click a button an event is fired from the client to the server. The event fires perfectly fine, but the OnServerEvent function is not working. Here is my script:
while true do
game.ReplicatedStorage.ClickEvent.OnServerEvent:Connect(function(player)
print("Clicked")
end)
wait()
end
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
function Click(plr)
ReplicatedStorage.ClickEvent:FireServer(player, plr)
print("Click Fired")
--click popup thingy
end
No need to use while loops with remoteevents here.
--This will simply run whenever the event is fired, could be multiple times
game.ReplicatedStorage.ClickEvent.OnServerEvent:Connect(function(player)
print("Clicked")
end)
Client:
local player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
function Click(plr)
ReplicatedStorage.ClickEvent:FireServer()
print("Click Fired")
end
Click(player)
When firing the server, no need to provide the player as an argument, it’s automatically there.