why works my script only by play solo? the script is in a screengui

player=game.Players.LocalPlayer character=player.Character mouse=player:GetMouse() clear={} obj=nil; bool_1=false; -->bool zum bewegen der box<-- bool_2=false while character==nil do wait() print("Load..") end -->WaitForChildCharacter()<-- function move_position() torso=character.Torso function check(box) for i=1,#box do if box[i]:IsA("Model") then if box[i].Name=="Box" then if box[i]:findFirstChild("Box")=nil then if box[i]:findFirstChild("Box"):findFirstChild("posi")=nil then part=box[i]:findFirstChild("Box") print(part) if (torso.Position-part.Position).Magnitude<=6 then bool_1=true

							obj=part
								print(obj)
						elseif (torso.Position-part.Position).Magnitude>=6 then
							bool_1=false
							obj=nil;
						end
					end
				end
			end
		end
	end
	
end
check(game.Workspace:GetChildren())

end

function key_down(Key) print(obj) move_position() if Key=="e" and obj~=nil then print(1) bool_2=true while bool_2==true do wait() print("eDown") function key_up(key) if key=="e" then bool_2=false if obj~=nil then obj.Anchored=true obj.posi.maxForce=Vector3.new(0,0,0) obj.posi.position=torso.Position end obj=nil;end end mouse.KeyUp:connect(key_up) --^^^^^^^^ break if key up^^^^^^^^-- if obj~=nil then obj.Anchored=false obj.posi.maxForce=Vector3.new(4000,4000,4000) obj.posi.position=torso.Position end end

end
end
mouse.KeyDown:connect(key_down)

2 comments

1

The most common cause for LocalScripts only working in a Local testing environment is not waiting for the player and character. You need to use wait() statements in a loop for LocalPlayer and player.Character because they don't exist immediately when the player joins,

0

You should make it as answer, duckwit.