Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

BindableEvent not firing / script not working?

Asked by 1 year ago

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!

0
Both scripts are regular scripts and not Local. hoppyman360 -13 — 1y
0
You put the "code thats inside the level" into every level right? Not just one? SnowieDev 171 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

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!

Ad

Answer this question