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.
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
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)
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.
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 disabledor parented to a service where server scripts won’t run. (Such as ServerStorage) Make sure the script is parented to ServerScriptService or Workspace