Overview
Hello, in this tutorial I will be teaching you how to make it so when a player steps on a part confetti appears above their head for a brief moment. In this tutorial we will be using a Particle Emitter, you can grab the model for the Particle Emitter below.
Confetti Model I use
Roblox API's Of Everything In This Script
The Setup
Step 1: You are gonna want to put your confetti in Server Storage:
Step 2: Add a new part into workspace, anchor it and add a server-script inside:
The Scripting
Alright, we’re gonna get into the fun part, scripting!
First of all, we’re gonna define all our variables:
local Part = script.Parent
-- ^ The part we walk on to trigger the confetti
local Confetti = game:GetService("ServerStorage"):WaitForChild("Confetti")
-- ^ The actual confetti
local Debounce = false
-- ^ Debounce so it .Touched triggered multiple times
Next, we’re gonna make a script that runs when the Part is Touched:
Part.Touched:Connect(function(hit)
-- ^ Connects function that happens when Part is touched (hit = what touches Part)
if hit.Parent:FindFirstChild("Humanoid") then
-- Only runs if hit is a player (Humanoid), and not anything else
end
end)
Were finally gonna clone the confetti into the workspace and make it above the players head and add debounce:
local Part = script.Parent
-- ^ The part we walk on to trigger the confetti
local Confetti = game:GetService("ServerStorage"):WaitForChild("Confetti")
-- ^ The actual confetti
local Debounce = false
-- ^ Debounce so it .Touched triggered multiple times
Part.Touched:Connect(function(hit)
-- ^ Connects function that happens when Part is touched (hit = what touches Part)
if hit.Parent:FindFirstChild("Humanoid") then
-- Only runs if hit is a player (Humanoid), and not anything else
if not Debounce then
Debounce = true
-- ^ Debounce
local Head = hit.Parent.Head
-- ^ Defines the head of hit.Parent
local ConfettiClone = Confetti:Clone()
-- ^ Makes a variable of the cloned confetti
ConfettiClone.Parent = workspace
-- ^ Puts the clone in workspace
ConfettiClone.CFrame = CFrame.new(Head.Position.X,Head.Position.Y+3,Head.Position.z)
-- ^ Sets the clones CFrame (Position) to above players head then
task.wait(1)
-- ^ Waits this amount and then does debounce again
ConfettiClone:Destroy()
Debounce = false
-- ^ Disables debounce, thus allowing player to do confetti again.
end
end
end)
Final Result
Here’s how it all came out, not the best but it’s a good little project you could do:
The End
Although this is a very simple script and definitely needs improvement, it should be a starting place for beginner scripters!
Raw script without comments:
local Part = script.Parent
local Confetti = game:GetService("ServerStorage"):WaitForChild("Confetti")
local Debounce = false
Part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
if not Debounce then
Debounce = true
local Head = hit.Parent.Head
local ConfettiClone = Confetti:Clone()
ConfettiClone.Parent = workspace
ConfettiClone.CFrame = CFrame.new(Head.Position.X,Head.Position.Y+3,Head.Position.z)
task.wait(1)
ConfettiClone.Parent = game.ServerStorage
Debounce = false
end
end
end)
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
0 voters
I spent an hour making this tutorial so I hope you learned something!