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)

2 comments
But if I don't use a local script that means I can't use TimePosition. :( Any ideas?
Yeah; put the LocalScript in StarterGui, and change
script.Parentto the absolute name of the Part. For instance,workspace.DoorModel.Partor whatever it is. It has to be unique, though, or it likely won't work.