I wanted to create a block that makes a sound and particle effects when you step on it.
Of course it does not work properly, I mean, it kind of does, but not always, one time when I turn the game on, it works perfectly, but another time, it glitches and the function which makes the script not repeat until the player moves away from the block does not work, resulting in a stack.
Here’s the info from the development console:
Error -- SoundScript is not a valid member of Part "Workspace.CeilingPanel"
Information -- Stack Begin
Information -- Script 'Workspace.CeilingPanel.RandomChance', Line 9 - function onTouched
Information -- Stack End
I tried a lot of different ways of fixing this issue, even entirely changing the script multiple times, but nothing worked, I really need help with fixing this issue.
Here’s the script itself:
script.Parent.Touched:Connect(function(h)
if h and h.Parent:FindFirstChild("Humanoid") then
script.Parent.CanTouch = false
script.Parent.Step:Play()
script.Parent.Smoke.Enabled = true
script.Parent.Particles.Enabled = true
wait(0.1)
script.Parent.Smoke.Enabled = false
script.Parent.Particles.Enabled = false
repeat wait() until game.Players:GetPlayerFromCharacter(h.Parent):DistanceFromCharacter(script.Parent.Position) > 8
script.Parent.CanTouch = true
end
end)
Warning -- Infinite yield possible on 'workspace.CeilingPanel:WaitForChild("SoundScript")'
Info -- Stack begin
Info -- Script 'Workspace.CeilingPanel.EffectScript', Line 1
info -- Stack End
That is what I get after implementing it, the script does not work anymore
Okay so, the other script known as RandomChance might be now causing the issue, it’s supposed to roll a random number and if it’s a 1 it would disable the EffectScript for a short amount of time, there’s a chance these two might sync in such a way that it causes the error, I did think of an other idea tho, I will make it into one script where if it rolls any number between 2 and 99, the normal thing happens, but if it rolls 1, the other thing will happen! I will do it now and test it.