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

Camera script for viewing cars not working?

Asked by 3 years ago
Edited 3 years ago

Hello, I have a script that is supposed to attach the car to an rc car. But It doesn't want to work. It still is attached to the character and nothing happens. There is no error in output. It is a localscript. I used remoteevents.

local clickDetector = script.Parent.ClickDetector

function onMouseClick()
    game.ReplicatedStorage.CamP406:FireServer()
end
clickDetector.MouseClick:connect(onMouseClick)

Receive (in startergui and is a server script)

local cam = game.Workspace.CurrentCamera
repeat wait() until game:service("ContentProvider").RequestQueueSize == 0 -- This waits until the game is loaded up
game.ReplicatedStorage.CamP406.OnServerEvent:connect(function(plr)
    cam.CameraSubject = game.Workspace.P406.Shell
    cam.CameraType = Enum.CameraType.Attach
end)


1 answer

Log in to vote
1
Answered by 3 years ago

Server script :

local clickDetector = script.Parent.ClickDetector

function onMouseClick(play)
    game.ReplicatedStorage.CamP406:FireClient(play,play)
end
clickDetector.MouseClick:connect(onMouseClick)

Local script :

remote =  game.ReplicatedStorage.CamP406
plr = game:GetService("Players").LocalPlayer
cam = workspace.CurrentCamera
remote.OnClientEvent:Connect(function(player)
    if player.UserId == plr.UserId then
        cam.CameraSubject = workspace.P406.Shell
        cam.CameraType = Enum.CameraType.Attach 
    end
end)

You should put LocalScript in StarterGui and put Server script in part with ClickDetector.

0
Thank you, it is working. squidiskool 208 — 3y
Ad

Answer this question