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

Camera Not Changing onTouch?

Asked by
Rynappel 212 Moderation Voter
4 years ago

I have a part in Workspace, and when you touch it. A remote event is supposed to fire, and a local script will recognize the fire, and then it will change the players camera. How ever, this script does not work. Would any body please help? Thank you :)

Server Script in Part:

script.Parent.Touched:Connect(function()
    game.ReplicatedStorage.Events.TutorialEvents.Tutorial1:FireServer()
end)

Local Script in StartGUI:

game.ReplicatedStorage.Events.TutorialEvents.Tutorial1.OnClientEvent:Connect(function()
    local player = game.Players.LocalPlayer
    local character = player.Character
    local camera = workspace.CurrentCamera
    camera.CameraType = Enum.CameraType.Scriptable
    camera.CFrame = workspace.CameraPOS1.CFrame
end)
0
Ill get to that in a sec AntoninFearless 622 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago
Edited 4 years ago

Here you go!

script in part:

script.Parent.Touched:Connect(function()
    local event = game.ReplicatedStorage:FindFirstChild('Tutorial1')
    event:FireAllClients()
end)

localscript in StarterGui:

game.ReplicatedStorage.Tutorial1.OnClientEvent:connect(function()
    local plr = game.Players.LocalPlayer
    local cam = workspace.CurrentCamera
    local char = plr.Character

    repeat wait()
        cam.CameraType = Enum.CameraType.Scriptable
    until cam.CameraType == Enum.CameraType.Scriptable
    cam.CFrame = workspace.CameraPOS1.CFrame
end)
0
ill try this soon, ill let you know if it works/doesbt work Rynappel 212 — 4y
0
Thanks i made some changes but thanks :D Rynappel 212 — 4y
0
No problem AntoninFearless 622 — 4y
Ad
Log in to vote
0
Answered by
bum5Br 97
4 years ago

You're firing the Server and not the Client. To fire the Client you should use FireClient instead of FireServer and pass the player as your argument. To get the player you have to first check if the Toucher has a Humanoid parent and then use GetPlayerFromCharacter with the Players Service. Your Server script would look like this:

Server Script in Part:

Players = game:GetService("Players") --Gets Player service

script.Parent.Touched:Connect(function()
if Victim.Parent:FindFirstChild("Humanoid") then --Checks if Toucher has a Humanoid
local Player = Players:GetPlayerFromCharacter(Victim.Parent) -- Gets Player 
    game.ReplicatedStorage.Events.TutorialEvents.Tutorial1:FireClient(Player) 
--Fires to said Player only
end
end)

I didn't test this though, so something might not work.

Answer this question