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

Why is this script only working in studio mode?

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

✓ Accepted answer

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)

5 comments

0

It's not a local script, and I want it so when somebody touched it that stuff happens to them.

0

Scripts can't use Players.LocalPlayer, see if you can get the Player some other way

0

How else could I find the player?

0

Touched gives the Part.

0

Refer to my edit.

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