Need Help with Obby Effects

I’m trying to make a script for my obby that adds a highlight and particle effect to the stage in front of the player. Then, when the player moves to that stage, the effects move to the next stage. The issue is that I don’t see the effects when I run the game. There are no errors. I have my leaderstats set up correctly and a DataStore to save the stage value. I have the effect in a folder in ReplicatedStorage. I’m guessing the problem is that I’m running this client-side, but I only want the effects to display for the client, otherwise the screen would get very messy. What am I doing wrong?

-- Services
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
	
-- Variables
local checkpoint = game:GetService("Workspace"):WaitForChild("checkpoints"):GetChildren()
local highlight = ReplicatedStorage:WaitForChild("effects"):WaitForChild("highlight")
local particles = ReplicatedStorage:WaitForChild("effects"):WaitForChild("greenParticles")
local player = Players.LocalPlayer
local plrStage = player:WaitForChild("leaderstats"):WaitForChild("Stage")
local currentStage
	
-- Functions
local function FindStage()
	for _, stage in pairs(checkpoint) do
		if stage:IsA("Part") then
			if tonumber(stage.Name) == plrStage.Value then
				return stage
			end
		end
	end
	print("Ran FindStage function")
end
	
local function StageChanged()
	for _, stage in pairs(checkpoint) do
		if stage:IsA("Part") then
			if tonumber(stage.Name) == plrStage.Value then
				currentStage = currentStage + 1
			end
		end
	end
	print("Ran StageChanged function")
end
	
local function AddEffects()
	local stage = FindStage()
		
	local cloneHighlight = highlight:Clone()
	local cloneParticles = particles:Clone()
		
	for _, v in pairs(checkpoint) do
		if v == tonumber(plrStage) + 1 then
			cloneHighlight.Parent = v
			cloneParticles.Parent = v
		end
	end
	print("Ran AddEffects function")
	return cloneHighlight, cloneParticles 
end
	
local function RemoveEffects()
	AddEffects(highlight, particles):Destroy()
	print("Ran RemoveEvents function")
end
	
local function Run()
	AddEffects()
	
	plrStage.Changed:Connect(function()
		StageChanged()
		if currentStage == plrStage.Value then
			RemoveEffects()
			AddEffects()
		end
	end)
	print("Ran Run function")
end
	
-- Runtime
Players.PlayerAdded:Connect(Run)
player.CharacterAdded:Connect(Run)
1 Like

If you’re using highlights, the part you’re parenting them to cannot be invisible (transparency cannot be 1) otherwise it will not show, as for the particles, if they’re particle emitters you will need to enable them (if they’re not enabled already)

local function AddEffects()
	local stage = FindStage()

	local cloneHighlight = highlight:Clone()
	local cloneParticles = particles:Clone()
	
	local Point = nil

	for _, v in pairs(checkpoint) do
		if v == tonumber(plrStage) + 1 then
			Point = v
		end
	end
	if Point ~= nil then
		cloneHighlight.Parent = Point
		cloneParticles.Parent = Point 
	end
	print("Ran AddEffects function")
	return cloneHighlight, cloneParticles 
end
1 Like

The stages aren’t invisible, and the particle effects are also enabled.

1 Like

is the function running at all / printing?

2 Likes

I haven’t tried, but I’ll do it in a bit. I’m busy rn. Thanks.

1 Like

The print statements aren’t running at all. Any idea why?

1 Like

I suggest doing the PlayerAdded event via the server and using remote events to fire to the specific client

2 Likes

I’ll try that. Would it still fire when the stage is changed?

1 Like

Why are you comparing Instances to numbers? Because instances are not numbers this will always return false. Maybe use the Instance’s name and tonumber it before comparing it with a number

Edit: The reason why your script might not be printing anything is probably because the WaitForChild takes too long and your script misses when the events fire. Also, you should remove the player-added event because if any player joins your function will run for no good reason. If I’m being honest, you only need the plrStage.Changed event only

1 Like

Thank you, I completely re-wrote the script using a different method, and it works now. Thank you for taking the time to write this.