I've got a game-breaking problem

Hello, everyone.

I’m trying to make a system in my game, where when you fail a level a revive or get kicked event happens. I just noticed an error though.

This is a very tedious system, but it was working so far. In my first script, I made a number value that updates to what number level you are on. That system worked very well. The reason I did it was so the game would know where to teleport the player after they buy the revive. In my second script, which is all of the places that the player touches or clicks that would make them “die”. When this happens, this will teleport the player to a place on the map, (only so the camera can stay where they died without them being there) and a remote event is fired to the player. I just realized after writing 200 lines of very repetitive, tedious, code, that it isn’t working. No output errors, just not working. I’ll show you the general idea of my scripts below, and if you want to ask questions you can. I won’t post the whole thing because it is so long.

This is what the code for level one is. Simple, but I had to do this for many many levels and lots of different types of event firings. This is the simplest one I could find.

-- Level 1 🔴🔴🔴
workspace.level11.ClickDetector.MouseClick:Connect(function()
event:FireClient(Player)
Player.Character.HumanoidRootPart.Position = workspace.ReviveBox.TP.Position
end)
workspace.level12.ClickDetector.MouseClick:Connect(function()
event:FireClient(Player)
Player.Character.HumanoidRootPart.Position = workspace.ReviveBox.TP.Position
end)
workspace.level13.ClickDetector.MouseClick:Connect(function()
event:FireClient(Player)
Player.Character.HumanoidRootPart.Position = workspace.ReviveBox.TP.Position
end)

Repetitive events.

I tried printing after the event and the teleport, nothing. Please help!!

(The player that the event is firing to is from a PlayerAdded event argument)

A way to shorten your code is to put all your levels in a folder if you do, here’s a snippet of code you can try:

local folder = your.folder.path
local numberOfChildren = folder:GetChildren()
for i = 1, #numberOfChildren,1 do
    folder["level" .. i].ClickDetector.MouseClick:Connect(function()
        event:FireClient(Player)
        Player.Character.HumanoidRootPart.Position = workspace.ReviveBox.TP.Position
    end)
end
1 Like

just put all of the levels in a folder, use a for loop and boom your code should be like 4 lines. All in all it should look something like this:

for _, v in pairs(workspace.LevelFolder:GetChildren()) do
V.ClickDetector.MouseClick:Connect(function()
event:FireClient(Player)
Player.Character.HumanoidRootPart.Position = workspace.ReviveBox.TP.Position
end)

Wrote it all in devforum so idk if it works

1 Like

I was going to do that, but the problem is not all “deaths” are from mouseclick events.

(And on top of efficiency, it still doesn’t work)

Do you mean the void? Or killbricks or wat.

edit: Are there any errors?

1 Like

Yes the others are basically all touched events
edit: no output errors

Then do the same thing as what I did in the code I provided just modify for the kill brick.

Hmm. Try printing after the for loop statement, and then try printing at the start of the function and end of the function. That should give us helpful info.

1 Like

Ok, I might do this, but I believe the same thing will happen.

Also, does changing roblox’s auto-indent make the code not run

Edit: For some reason I just decided to make it all press to the left for this script cause it wwas so long -

I don’t believe so. But just indent to make sure. It shouldn’t make it not run but lol

2 Likes

Assuming absolutely nothing is running, like not even a print statement at the top of the script,
the cause is probably either the script being disabled or parented to a service where server scripts won’t run. (Such as ServerStorage) Make sure the script is parented to ServerScriptService or Workspace

note: this isn’t accounting for RunContext

1 Like

Indents may impact intellisense but it will still run perfectly fine without

2 Likes

theres an auto indent feature on the top.

Also your script editor color scheme is… questionable to say the least.

2 Likes

Lol. I like it. The defaults hurt my eyes.

Edit:

This is what the scripts look like. (Its titled “main”)
image

1 Like

Also guys its still not working so do you have any other solutions or am I just doomed

@Earthraphobic2 I seriously don’t know what to do please help

Remove the wait(1) at the top of the script & change your teleports to use CFrame instead of Positions

If this doesn’t fix the issue, put prints at these locations and let us know what isn’t running.
image

1 Like

HOLY HELL!!

Ironically, I had thought just before I even saw this, “Heck, I’ll just remove the wait.”

And it WORKED!!!

Thank you!! (How come this worked?)

1 Like

The PlayerAdded event was being connected after the player joined. (They joined during the 1 second of delay)

1 Like

Ohhh… This makes sense now, I’m such an idiot. Thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.