I have a checkpoint system in my game. What I need to achieve is that the part should go from 0 to 1 then 1 to 0 transparency just like a glow effect and a checkpoint sound to play, I want it to happen only once for each player locally on each checkpoint.
What I did:
local SoundName = "Checkpoint"
local use = false
local Sound = script.parent:FindFirstChild(SoundName)
script.parent.Touched:Connect(function(hit)
if use == false then
use = true
script.parent.Material = "Neon"
Sound:play()
local x = 20
while wait(.2) do
if x > 0 then
x = x - 1
script.parent.Transparency = script.parent.Transparency - 0.1
else
break
end
end
script.parent:Destroy()
end
end)
The problem with this was that it only did it for one player [Probably because Destroy()?] and that I wanted it to be locally for all players.
I ain’t sure how do I achieve this and Is there a better way of doing the glow effect I am going for?
One way you could do this is by having a ModuleScript in each part which you require from a LocalScript that’s parented to StarterPlayerScripts or so. This is the easiest way I thought of.
ModuleScripts are really easy to use, actually.
For the ModuleScript initialization, you could do something like this:
local Funcs = {}
Funcs.init = function()
--add touched events and so on
end
return Funcs
--how the modules would be initialized
local Checkpoints = workspace:WaitForChild("Checkpoints")
function initCheckpoint(v)
local ModuleToRequire = v:WaitForChild("InitModule", 1) --name the module whatever
if ModuleToRequire then --notice how theres a timeout to the waitforchild, since the for loop is checking it can't take all the time
local Required = require(ModuleToRequire)
spawn(Required.init)
end
end
for _,v in pairs(Checkpoints:GetChildren()) do
initCheckpoint(v)
end
Checkpoints.ChildAdded:Connect(initCheckpoint)
About the glow effect, I got some help and tween actually worked much better.
This doesn’t work fully like only goes to transparency 1 and then stops, but yeah.
local tweens = game:GetService("TweenService")
local use = false
script.Parent.Touched:Connect(function(hit)
if use == false then
local tween = tweens:Create(script.Parent,TweenInfo.new(1),{Transparency = 0})
tween:Play()
tween.Completed:Wait()
local tween = tweens:Create(script.Parent,TweenInfo.new(1),{Transparency = 1})
tween.Completed:Wait()
use = true
end
end)
I have a similar thing. What I did is put is in replicated storage. When ever I want to call it, I just clone it from the player’s local script and set the location. It then just does it’s thing oblivious to anything else. But only the local player can see it because they cloned it.
I do the same with spell FX except they are called by the server so everyone can see it.
Really it’s a single block part. Inside I have the script for the part, and the particle emitter if I need it. The code instantly plays out.
I had an issue with setting the brightness of the glow though so what I did was have light 10 light sources and just enabled and disabled them at will. Wasn’t perfect for the smoothness but if people don’t really focus on it, they can’t see the steps. That was me though.
You can make this local by either using a local script or in the server script firing a remote event to the client who touched it and running the effect code on the client.