Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to put different music in different zones WITHOUT lag?

Asked by 6 years ago
Edited 6 years ago

Alright. So. I'm using a cat model (custom made, rigged and animated) And when I try to make a sound area, using this script- (Courtesy of probiker123)

-- LocalScript
local sound = workspace:WaitForChild("Sound")
local hitbox = workspace:WaitForChild("Area1") -- Assuming we have a part in workspace called Area1
hitbox.Touched:Connect(function(part)
   if part.Name == "Head" and part.Parent.Name == game.Players.LocalPlayer.Name then
      sound.SoundId = "rbxassetid://" .. "Your sound ID"
      sound:Play() -- Highly recommended to loop the sound
      hitbox.TouchEnded:Wait() -- Yields the script until the part isn't touched anymore 
      sound:Stop()
   end
end)

Before I even put in the script for the block, when I press play, the model lags like crazy. How do I fix this?

0
If it's this script that is causing the lag, it's because you're standing on the hitbox, and it's firing the Touched event rapidly. Gey4Jesus69 2705 — 6y

Answer this question