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)
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)
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.