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

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

Asked by
Nidoxs 190
9 years ago

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

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

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?

0
But if I don't use a local script that means I can't use TimePosition. :( Any ideas? Nidoxs 190 — 9y
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. adark 5487 — 9y
Ad
Log in to vote
-2
Answered by 9 years ago

Because LocalScripts and Scripts are two different things

Answer this question