Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Camera Not Changing onTouch?

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)

1 comment

0

Ill get to that in a sec

2 answers

✓ Accepted answer

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)

3 comments

0

ill try this soon, ill let you know if it works/doesbt work

0

Thanks i made some changes but thanks :D

0

No problem

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.