Hello there.
I am was working on a game and ran into a really big problem. My game is a horror game and for one of features there is a radio. When you hold the ProximityPrompt on the radio it begins playing a song. I wanted the players camera to switch and focus on the radio. After making all the scripts I realized a problem. The ProximityPrompt is in Workspace and uses a script, while the receiving local script is in StarterPlayerScripts. I decided to go the route of using a event. I tried to use a Remote Event but it didn’t work because it was not sent from the client. I then attempted a Bindable Event which worked, but the change camera script has to be a local script to work. So I am kind of stuck. Does anyone think they can help me? I do not know what to do and I suck at scripting. Thanks.
Remote events are the right answer here. How exactly were you trying to use them?
Just before I make the script. Would you like this “cutscene” to be only localy visible or something for everyone to see?
When a player triggers a ProximityPrompt, you can grab the specific player using something like this:
ProximityPrompt.Triggered:Connect(function(player)
--Code goes here
end
You can use this to make changes to the specific player just like a LocalScript. For example, you could do this to make you go first person when you trigger the Prompt:
ProximityPrompt.Triggered:Connect(function(player)
player.CameraMode = Enum.CameraMode.LockFirstPerson
end
I think you could do this:
This is the script on the prompt on the Workspace.
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.CameraSwitch
script.Parent.Triggered:Connect(function(player)
RemoteEvent:FireClient(player, "Triggered")
end)
This is the local script which will recieve the Event:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("CameraSwitch")
RemoteEvent.OnClientEvent:Connect(function(player, response)
if player then
player.CameraMode = Enum.CameraMode.LockFirstPerson
player.CameraType = Enum.CameraType.Scriptable
-- Here you can change CFrame of the camera.
end
end)
PS: Also If your prompt doesn’t have a hold duration time I suggest you put a debounce / cooldown because players could trigger it twice and glitch the whole system.
The game is single player, so it only needs to work for one person.
I was trying to fire an event from a script in Workspace to a local script in StarterPlayerScripts.
I got an error that says " Players.CrispyTRCS.PlayerScripts.LocalScript:8: attempt to index string with ‘CameraMode’ - Client - LocalScript:8"
Sorry for the late response,
Here’s something that should work out:
Workspace Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage.CameraSwitch
script.Parent.Triggered:Connect(function(player)
RemoteEvent:FireClient(player)
end)
Local Script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("CameraSwitch")
local Camera = workspace.CurrentCamera
RemoteEvent.OnClientEvent:Connect(function()
Camera.CameraMode = Enum.CameraMode.LockFirstPerson
Camera.CameraType = Enum.CameraType.Scriptable
-- Here you can change CFrame of the camera.
end)
Thank you so much, it worked. Have a good day!