How do I clone a confetti part for obby checkpoints?

Hi! I tried cloning a confetti part when a player reaches a next checkpoint in an obby, but I keep getting the attempt to call an Instance value error.

I made an event fire from a ServerScript, then the part in replicatedstorage would be cloned into the checkpoint part from StarterPlayerScripts, and it’s not working for some reason.

Script:


local rs = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local leaderstats =  player:WaitForChild("leaderstats"):FindFirstChild("Stage").Value
rs.Confettievent.OnClientEvent:Connect(function()
	local clone = rs.Confetti:Clone()
	clone.Parent = game.Workspace.checkpoints(leaderstats)
	wait(2.5)
	clone:Destroy()
end)

Does anyone know how to fix this error? Thank you!

clone.Parent = game.Workspace.checkpoints[leaderstats]

Use square brackets to directly reference a child instead of parentheses.

1 Like

The confetti shows up, but it won’t clone to the second checkpoint when the player reaches it, instead showing in the first one. Is there a way to change the location of the confetti as the player reaches every next checkpoint?

Try getting the value of this inside the event. You’re getting it once, but you never get it again!

local rs = game:GetService("ReplicatedStorage")
local player = game.Players.LocalPlayer
local leaderstats =  player:WaitForChild("leaderstats")

rs.Confettievent.OnClientEvent:Connect(function()
	local clone = rs.Confetti:Clone()
	clone.Parent = game.Workspace.checkpoints[leaderstats:FindFirstChild("Stage").Value]
	wait(2.5)
	clone:Destroy()
end)

For some reason, it still keeps replicating in the first stage only, even after checking for the stage value later

That’s pretty interesting… Could you confirm that the Stage value is actually incrementing? And if so, could you also confirm that the names of the checkpoints are actually just linearly incrementing numbers?

You said it is a part, so you need to change the part position to be at the selected checkpoint position.

-- Roblox Services
local PlayerService = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Main Instances
local Player = PlayerService.LocalPlayer
local Leaderstats = Player:WaitForChild("leaderstats")
local Stage = Leaderstats:WaitForChild("Stage")

local ConfettiEvent = ReplicatedStorage.Confettievent
local ConfettiPart = ReplicatedStorage.Confetti

local Checkpoints = workspace:WaitForChild("checkpoints")

-- Main Connections
ConfettiEvent.OnClientEvent:Connect(function()
	local NewConfetti = ConfettiPart:Clone()
	NewConfetti.Parent = workspace
    NewConfetti.Position = Checkpoints:FindFirstChild(Stage.Value).Position
	task.wait(2.5)
	NewConfetti:Destroy()
end)
1 Like

Thanks for helping! it works perfectly

1 Like

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