Script doesn't work has expected

  1. What do you want to achieve? I made a simple script to enable a server script in the map after voting

  2. What is the issue? It doesnt work and stays on the print("Script is starting")

  3. What solutions have you tried so far? i tried changing things but doesn’t work

local RunService = game:GetService("RunService")
local mainMap = workspace.Map:FindFirstChildOfClass("Folder")
local canWarn = true

local function setMapServerScripts()
	print("Script is starting")
	if mainMap then
		print("Script started")
		local waypointsSetUp = mainMap:FindFirstChild("WaypointsSetUp")
		if waypointsSetUp then
			print("Script finished")
			waypointsSetUp.Enabled = true
		elseif canWarn then
			warn("WaypointsSetUp not found inside map!")
			canWarn = false
		end
	end
end

RunService.Heartbeat:Connect(setMapServerScripts)
1 Like

I think it can’t find the mainMap Folder, it would run the rest if it did, but it doesn’t, maybe check if it exists and wait when it loads, otherwise Im not sure.

I did that, i called the function 1 second after map spawned, still doesn’t work

I also checked if game is running (after everything from vote is done map spawned etc) still doesn’t work, map is not nil but the script doesn’t find it, idk what’s happening, i need help

please may you screenshot the explorer layout of the map so we can better understand the issue?

Server Scripts only run at startup i believe. You should use a remote event to set up the waypoints after the map has been loaded and is ready.

Why are you running that function every single frame, it is not the reason it doesn’t work but that’s just cursed

1 Like

I can’t give a screenshot because i’m not in my pc right now but basically the map is in ServerStorage.Maps, when someone plays they need to vote for map and after that the choosen map from ServerStorage moves to workspace.Map which is why i use FindFirstChildOfClass(“Folder”) cuz different maps names

I changed that after some mins after posting this, i called it 1 time that didn’t change anything

Alright, does putting a breakpoint on if waypointsSetUp then do anything?

nope but somehow i fixed it by defining mainMap at the function, idk why this fixes it, i also changes alot of things

local RunService = game:GetService("RunService")
local votingGamemode = workspace.Info.GamemodeVoting
local mapFolder = workspace.Map or workspace:WaitForChild("Map")
local mainMap
local canWarn = true
local foundScript = false

local function setMapServerScripts()
--	print("Script is starting")
	mainMap = mapFolder:FindFirstChildOfClass("Folder")
	if mainMap then
--		print("Script started")
		
		for _, descendant in pairs(mainMap:FindFirstChild("Scripts"):GetDescendants()) do
			if descendant:IsA("Script") then
--				print("Script finished")
				descendant.Enabled = true
				foundScript = true
			end
		end
		
		if not foundScript and canWarn then
			warn("No server scripts found inside map!")
			canWarn = false
		end
		
		return true
	end
	return false
end

votingGamemode:GetPropertyChangedSignal("Value"):Connect(function()
	if votingGamemode.Value == true then
		RunService.Heartbeat:Wait()
		setMapServerScripts()
	end
end)

I guess it never defined then, that’s just odd, happy you found a solution

1 Like

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