Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

BindableEvent not firing / script not working?

Hi, I just want to start off by saying I'm pretty new to programming, so apologies if any of this code is inefficient/pointless, I just want to take care of this one-event problem and that's it.

So my problem is that when a level generates in my game, I want it to fire a BindableEvent (client to client right?) event in the level, and the script in that level waits for the event to be fired to do its functions.

The event fires like normal, and no errors are in the output, here's the code for the function that fires the event.

local function LoadLevel()
	if IsLevelLoaded.Value == false then
		local Levels = ReplicatedStorage.Levels:GetChildren()
		local AmountOfLevels = #Levels
		local RandomPositionInArray = math.random(1, AmountOfLevels)
		local RandomLevel = Levels[RandomPositionInArray]
		local Clone = RandomLevel:Clone()
		Clone.Parent = game.Workspace
		local NameOfCurrentLevel = RandomLevel.Name
		print(NameOfCurrentLevel) 
		IsLevelLoaded.Value = true
		RandomLevel.LevelStart:Fire() --for clarification, each level will have the event inside.
	else
		print("Level is already loaded")
	end
end

LoadLevel()

and here's the code for inside the level

local LevelStart = script.Parent.LevelStart

LevelStart.Event:Connect(function()
	print("test")
end)

Again, there are no errors in the output, but the "test" isn't being printed into the output. Why? Hope it's something simple.

Thank you for your help and happy holidays!

2 comments

0

Both scripts are regular scripts and not Local.

0

You put the "code thats inside the level" into every level right? Not just one?

1 answer

So I troubleshooted the problem myself and found out the script wasn't even working because it was in ReplicatedStorage. The fix was to move it to Workspace. I didn't know that scripts don't execute in ReplicatedStorage, but after that everything worked fine!

This discussion is preserved as it was. New answers, comments, and votes are closed.