Somehow a function fires out of nowhere

Hello!

While developping my game, this happened:

  • I have a RemoteEvent in ReplicatedStorage
    -A local script that fires a function from a module script (where’s the weird bug) (StarterGUI)
  • A module script in StartGUI that has a function

The function fires weirldy. I remove things one by one and when I “--”, the function isn’t fired.

This is the local script

local GUI = script.Parent.Parent

done = false

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local ReplicatedFirst = game:GetService("ReplicatedFirst")

local CoolJump = ReplicatedStorage.JumpScareFolder.CoolJump

local Credits = require(GUI:WaitForChild("Jumpscares"))

CoolJump.OnClientEvent:Connect(Credits.GameOver("im cool","got u","he he"))

This is in the module script (I remove some codes just to make things simpler.

local Credits = {}

function Credits.GameOver(LineOne, LineTwo, LineThree)

end

return Credits

Can anyone tell me what is happening?

The reason this is firing “out of nowhere” is because you are calling the function GameOver instead of actually creating a connection to the event. In this case you would have to connect an anonymous function in order to establish a proper script connection.

CoolJump.OnClientEvent:Connect(function()
    Credits.GameOver("im cool","got u","he he")
end)
1 Like

Thank you for your help! I was really confused by what I was doing wrong. :smile:

1 Like