You can write your topic however you want, but you need to answer these questions:
What do you want to achieve?
I want a remote event to fire when I click a GUI element
What is the issue?
The event fires when the game starts, and throws an error when the button is clicked
It would be good to note that the GUI element parenting the button and script is being cloned, as originally it is kept in replicatedStorage.
local interactionServerEvent = game.ReplicatedStorage.remoteEvents.statusBarInteraction
function interactionSend(button)
print("Firing Server")
interactionServerEvent:FireServer(script.Parent.Name, button)
end
script.Parent.InteractionA.MouseButton1Click:Connect(interactionSend("InteractionA"))
and when the button is clicked: attempt to call a nil value.
Instead of connecting the event to the function, you call the function inside the event brackets, you should instead do:
local interactionServerEvent = game.ReplicatedStorage.remoteEvents.statusBarInteraction
function interactionSend(button)
print("Firing Server")
interactionServerEvent:FireServer(script.Parent.Name, button)
end
script.Parent.InteractionA.MouseButton1Click:Connect(function()
interactionSend("InteractionA")
end)
When connecting a function to events, you aren’t supposed to call it. You basically have to connect the function itself, not the result returned by it.
When you were doing this: script.Parent.InteractionA.MouseButton1Click:Connect(interactionSend("InteractionA"))
All that the interpreter sees is:
Call interactionSend with “InteractionA”
Return the value (which is nil) into Connect.