Why is this LocalScript is running for all of the clients in the game?
I'm new to Roblox Lua, but I do have experience in other languages including C, C++, Java, Python. I'm having a problem with this localscript. I want the localscript to work like this: When a player touches this block it changes the camera view to somewhere else. Instead of doing that it changes the camera view for ALL the players in the server. Here is the localscript:
(It is in StarterGui)
01 | local cam = workspace.Camera |
02 | local player = game.Players.LocalPlayer |
03 | local focus = game.Workspace.col 1 |
04 | local tween = game:GetService( "TweenService" ) |
07 | game.Workspace.Shop.Touched:Connect( function (hit) |
10 | local humanoid = hit.Parent:FindFirstChild( "Humanoid" ) |
11 | local root = hit.Parent:FindFirstChild( "HumanoidRootPart" ) |
13 | if humanoid ~ = nil then |
14 | humanoid.WalkSpeed = 0 |
15 | cam.CameraType = Enum.CameraType.Scriptable |
16 | local ts = TweenInfo.new( 0.0001 ,Enum.EasingStyle.Quad,Enum.EasingDirection.In, 0 , false , 0 ) |
17 | local Goals = { CFrame = focus.CFrame } |
18 | local move = tween:Create(cam,ts,Goals) |
21 | root.CFrame = game.Workspace.queue.CFrame |
25 | local buttons = Instance.new( "ScreenGui" ) |
26 | local Frame = Instance.new( "Frame" ) |
27 | local back = Instance.new( "ImageButton" ) |
28 | local front = Instance.new( "ImageButton" ) |
29 | local home = Instance.new( "TextButton" ) |
31 | buttons.Name = "buttons" |
32 | buttons.Parent = game.Players.LocalPlayer:WaitForChild( "PlayerGui" ) |
33 | buttons.ZIndexBehavior = Enum.ZIndexBehavior.Sibling |
35 | Frame.Parent = buttons |
36 | Frame.BackgroundColor 3 = Color 3. fromRGB( 255 , 255 , 255 ) |
37 | Frame.BackgroundTransparency = 1.000 |
38 | Frame.Size = UDim 2. new( 0 , 100 , 0 , 100 ) |
42 | back.BackgroundColor 3 = Color 3. fromRGB( 0 , 0 , 0 ) |
43 | back.Position = UDim 2. new( 0 , 0 , 3.05000019 , 0 ) |
44 | back.Size = UDim 2. new( 0 , 73 , 0 , 84 ) |
45 | back.Rotation = 180.000 |
47 | back.BackgroundTransparency = 1 |
51 | front.BackgroundColor 3 = Color 3. fromRGB( 0 , 0 , 0 ) |
52 | front.Position = UDim 2. new( 11.1300001 , 0 , 3.05000019 , 0 ) |
53 | front.Size = UDim 2. new( 0 , 73 , 0 , 84 ) |
55 | front.BackgroundTransparency = 1 |
59 | home.BackgroundColor 3 = Color 3. fromRGB( 244 , 80 , 255 ) |
60 | home.Position = UDim 2. new( 4.91000032 , 0 , 7.48000002 , 0 ) |
61 | home.Size = UDim 2. new( 0 , 267 , 0 , 66 ) |
62 | home.Font = Enum.Font.SourceSans |
63 | home.Text = "Back Home" |
64 | home.TextColor 3 = Color 3. fromRGB( 0 , 0 , 0 ) |
65 | home.TextScaled = true |
66 | home.TextSize = 14.000 |
67 | home.TextWrapped = true |
69 | player.PlayerGui.buttons.Frame.home.MouseButton 1 Click:Connect( function (player) |
70 | cam.CameraType = Enum.CameraType.Custom |
71 | script.Parent.buttons:Destroy() |
72 | humanoid.WalkSpeed = 16 |
76 | script.Parent.buttons.Frame.front.MouseButton 1 Click:Connect( function (player) |
78 | Iterator = Iterator + 1 |
79 | local count = tostring (Iterator) |
80 | local val = "col" ..count |
81 | local focus 2 = game.Workspace:WaitForChild( tostring (val)) |
82 | local ts 2 = TweenInfo.new( 2 ,Enum.EasingStyle.Quad,Enum.EasingDirection.In, 0 , false , 0 ) |
83 | local Goals 2 = { CFrame = focus 2. CFrame } |
84 | local move 2 = tween:Create(cam,ts 2 ,Goals 2 ) |