Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

It works in a script but not a LocalScript. Why is this?

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 answers

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?

2 comments

0

But if I don't use a local script that means I can't use TimePosition. :( Any ideas?

0

Yeah; put the LocalScript in StarterGui, and change script.Parent to the absolute name of the Part. For instance, workspace.DoorModel.Part or whatever it is. It has to be unique, though, or it likely won't work.

Because LocalScripts and Scripts are two different things

This discussion is preserved as it was. New answers, comments, and votes are closed.