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

Why is this LocalScript is running for all of the clients in the game?

Asked by 5 years ago

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)

01local cam = workspace.Camera
02local player = game.Players.LocalPlayer
03local focus = game.Workspace.col1
04local tween = game:GetService("TweenService")
05local active = false
06 
07game.Workspace.Shop.Touched:Connect(function(hit)
08    if not active then
09        active = true
10        local humanoid = hit.Parent:FindFirstChild("Humanoid")
11        local root = hit.Parent:FindFirstChild("HumanoidRootPart")
12        Iterator = 1
13        if humanoid ~= nil then
14            humanoid.WalkSpeed = 0
15            cam.CameraType = Enum.CameraType.Scriptable
View all 94 lines...
1
use workspace.CurrentCamera, not Camera proqrammed 285 — 5y
0
That script is a listener for events happening. Whenever the block is touched, doesn't matter who touched it, it will run on all clients. Try changing to to a server script and getting the player from the character. killerbrenden 1537 — 5y
0
@killerbrenden good idea, i didnt think of that proqrammed 285 — 5y
0
@killerbrenden It works when I make it into a script but it will not change the cameratype to scriptable even when I tell it to, the cameratype remains custom IProgram_CPlusPlus 58 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

How do I fix this???

@killerbrendan and @ProqrammedGreen Everything works excepts for the camera, the camera will not move to where I want it to go, it remains a normal camera. Here is the new code:

01local cam = workspace.Camera
02local focus = game.Workspace.col1
03local tween = game:GetService("TweenService")
04local active = false
05 
06game.Workspace.Shop.Touched:Connect(function(hit)
07    if not active then
08        active = true
09        local humanoid = hit.Parent:FindFirstChild("Humanoid")
10        local player = game.Players:GetPlayerFromCharacter(hit.Parent)
11        local root = hit.Parent:FindFirstChild("HumanoidRootPart")
12        Iterator = 1
13        if humanoid ~= nil then
14            humanoid.WalkSpeed = 0
15            cam.CameraType = Enum.CameraType.Scriptable
View all 94 lines...
Ad

Answer this question