It works in a script but not a LocalScript. Why is this, and how do I fix it?
local db = false function onTouched(Part) if db then return end db = true if Part.Parent:FindFirstChild("Humanoid") and game.Players:GetPlayerFromCharacter(Part.Parent) then local plr = game.Players:GetPlayerFromCharacter(Part.Parent) if plr.PlayerGui:FindFirstChild("onTouchSound") then return end local sound = script.Sound:Clone() local a = script.ScreenGui:Clone() a.Parent = plr.PlayerGui sound.Parent = plr.PlayerGui sound.Name = "onTouchSound" sound.TimePosition = 74.8 sound:Play() sound.TimePosition = 74.8 for i = 0, 1, .01 do sound.Volume = i wait() end end wait(2) db = false end script.Parent.Touched:connect(onTouched)
LocalScript only run in three places: a Player's Backpack, their PlayerGui, and their Character model.
I assume that this script doesn't work in a LocalScript because you're placing it inside a brick inside of the Workspace, correct?