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

Why is this script only working in studio mode?

Asked by
Zelnus 30
8 years ago
scriptRunning = false 

script.Parent.Touched:connect(function()
    if scriptRunning then
        print 'Running'
    end
    if not scriptRunning then
        scriptRunning = true
        wait(0.1)
        game.Workspace.Tube.Transparency = 0.9
        game.Workspace.Tube.Transparency = 0.8
        wait(2)
        game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 0
        game.Players.LocalPlayer.Character.Torso.CFrame = game.Workspace.Center.CFrame
        wait(1)
    game.Lighting.ParticleEmitter:Clone().Parent = game.Players.LocalPlayer.Character.Torso
    game.Lighting.ParticleEmitter:Clone().Parent = game.Players.LocalPlayer.Character["Right Arm"]
    game.Lighting.ParticleEmitter:Clone().Parent = game.Players.LocalPlayer.Character["Left Arm"]
    wait(4)
    game.Players.LocalPlayer.Character["Right Leg"].Transparency = 0.2
    game.Players.LocalPlayer.Character["Left Leg"].Transparency = 0.2
    wait(0.1)
    game.Players.LocalPlayer.Character["Right Leg"].Transparency = 0.4
    game.Players.LocalPlayer.Character["Left Leg"].Transparency = 0.4
    wait(0.1)
    game.Players.LocalPlayer.Character["Right Leg"].Transparency = 0.6
    game.Players.LocalPlayer.Character["Left Leg"].Transparency = 0.6
    wait(0.1)
    game.Players.LocalPlayer.Character["Right Leg"].Transparency = 0.8
    game.Players.LocalPlayer.Character["Left Leg"].Transparency = 0.8
    wait(0.1)
    game.Players.LocalPlayer.Character["Right Leg"].Transparency = 1
    game.Players.LocalPlayer.Character["Left Leg"].Transparency = 1
    wait(0.1)
    game.Players.LocalPlayer.Character["Right Arm"].Transparency = 0.2
    game.Players.LocalPlayer.Character["Left Arm"].Transparency = 0.2
    game.Players.LocalPlayer.Character["Torso"].Transparency = 0.2
    wait(0.1)
    game.Players.LocalPlayer.Character["Right Arm"].Transparency = 0.4
    game.Players.LocalPlayer.Character["Left Arm"].Transparency = 0.4
    game.Players.LocalPlayer.Character["Torso"].Transparency = 0.4
    wait(0.1)
    game.Players.LocalPlayer.Character["Right Arm"].Transparency = 0.6
    game.Players.LocalPlayer.Character["Left Arm"].Transparency = 0.6
    game.Players.LocalPlayer.Character["Torso"].Transparency = 0.6
    wait(0.1)
    game.Players.LocalPlayer.Character["Right Arm"].Transparency = 0.8
    game.Players.LocalPlayer.Character["Left Arm"].Transparency = 0.8
    game.Players.LocalPlayer.Character["Torso"].Transparency = 0.8
    wait(0.1)
    game.Players.LocalPlayer.Character["Torso"].ParticleEmitter.Enabled = false
    game.Players.LocalPlayer.Character["Right Arm"].ParticleEmitter.Enabled = false
    game.Players.LocalPlayer.Character["Left Arm"].ParticleEmitter.Enabled = false
    game.Players.LocalPlayer.Character["Right Arm"].Transparency = 1
    game.Players.LocalPlayer.Character["Left Arm"].Transparency = 1
    game.Players.LocalPlayer.Character["Torso"].Transparency = 1
    wait(0.1)
    game.Players.LocalPlayer.Character["Head"].Transparency = 0.2
    game.Players.LocalPlayer.Character.Head["face"].Transparency = 0.2
    game.Players.LocalPlayer.Character.Head["face"].Transparency = 0.2
    wait(0.1)
    game.Players.LocalPlayer.Character["Head"].Transparency = 0.4
    game.Players.LocalPlayer.Character.Head["face"].Transparency = 0.4
    wait(0.1)
    game.Players.LocalPlayer.Character["Head"].Transparency = 0.6
    game.Players.LocalPlayer.Character.Head["face"].Transparency = 0.6
    wait(0.1)
    game.Players.LocalPlayer.Character["Head"].Transparency = 0.8
    game.Players.LocalPlayer.Character.Head["face"].Transparency = 0.8
    wait(0.1)
    game.Players.LocalPlayer.Character["Head"].Transparency = 1
    game.Players.LocalPlayer.Character.Head["face"].Transparency = 1
    wait(0.1)
    local d = game.Players.LocalPlayer.Character:GetChildren() 
    for i=1, #d do 
        if (d[i].className == "Hat") then 
            d[i].Handle.Transparency = 1
        end 
    end
    wait(7)
    game.Workspace.Tube.Transparency = 0.9
    game.Workspace.Tube.Transparency = 1

end 
end)

1 answer

Log in to vote
-1
Answered by 8 years ago

LocalScripts have to go in the Player; they won't run inside of Workspace unless you're in Studio.

Scripts can't use Players.LocalPlayer

In your case, you need to look at using the part from Touched.

thing.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent);
if player then
-- player is now the Player that touched it
end
end)
0
It's not a local script, and I want it so when somebody touched it that stuff happens to them. Zelnus 30 — 8y
0
Scripts can't use `Players.LocalPlayer`, see if you can get the Player some other way User#6546 35 — 8y
0
How else could I find the player? Zelnus 30 — 8y
0
Touched gives the Part. User#6546 35 — 8y
0
Refer to my edit. User#6546 35 — 8y
Ad

Answer this question