[SOLVED] Why does this script still remove when there is no cutscene in this folder?

Notes

  1. If I ever say Argument, it means the value that it gets from the GUI Button I’m pressing.

Alright, what my script is suppose to do is if it finds a the name of the script it has in the argument then it will delete all scripts inside of the Cutscene Folder for the PlayerGui.
Otherwise it will clone and copy the argument and move that copy to the Cutscenes Folder inside of the PlayerGui.

The script works but after I let the Cutscene play and it deletes itself as it’s programmed to do… if I hit it again, it adds the cutscene but in a matter of a second it then does the first statement which deletes and fixes the players Camera…

I have tried rewriting the entire statement to see if that would fix and it didn’t.
I’ve been at this all night and I have no idea what I can do to prevent this.
Here’s a link to a YouTube Video I made showing the issue.
The little end at the bit where the Camera gets fixed even though the script is removed from my Cutscenes Folder, that’s the issue.

Any help is appreciated!

Issue Part

	if Play == "On" then
		for i,x in pairs (game.Players:GetPlayers()) do
			if x.PlayerGui.Cutscenes:FindFirstChild(""..argument) then
				x.PlayerGui.Cutscenes:ClearAllChildren()
				FixCam.FixCamera.Disabled = false
				FixCam.FixCamera:Clone().Parent = x.PlayerGui.Cutscenes
			else
				Cutscene:FindFirstChild(""..argument):Clone().Parent = x.PlayerGui.Cutscenes
				x.PlayerGui.Cutscenes:FindFirstChild(""..argument).Disabled = false
			end
		end

Entire Script

--Made By MillerrIAm
-------------------Variables------------------
Cutscene = game:GetService("ServerStorage").Cutscenes
FixCam = game:GetService("ServerStorage").ExtraItems
Event = game.ReplicatedStorage.GUIEvents.CutscenePlayer
Camera = game.Workspace.CurrentCamera
------------------Main Script------------------
Event.OnServerEvent:Connect(function(plr,Play,argument)
	if Play == "On" then
		for i,x in pairs (game.Players:GetPlayers()) do
			if x.PlayerGui.Cutscenes:FindFirstChild(""..argument) then
				x.PlayerGui.Cutscenes:ClearAllChildren()
				FixCam.FixCamera.Disabled = false
				FixCam.FixCamera:Clone().Parent = x.PlayerGui.Cutscenes
			else
				Cutscene:FindFirstChild(""..argument):Clone().Parent = x.PlayerGui.Cutscenes
				x.PlayerGui.Cutscenes:FindFirstChild(""..argument).Disabled = false
			end
		end
	elseif Play == "Off" then
		for i,x in pairs (game.Players:GetPlayers()) do
			x.PlayerGui.Cutscenes:ClearAllChildren()
			i = FixCam.FixCamera
			i.Disabled = false
			i:Clone().Parent = x.PlayerGui
		end
	end
end)
print("ScriptWorking")

Why are you handling GUIs on the serverside?

I’m not, this is powered through a RemoteEvent which makes it so the Client can interact with the Server.

I think what @Ukendio was trying to say, was that in general a lot of the server side stuff could be handled on the client. I think it’s good practice to keep certain aspects of your game out of the clients hands unless absolutely necessary, but in this instance it might be better for the client to just control it all rather than having to clone a fix camera script each time.

Speaking of that script, I have a couple of suggestions why this might not be working:

  1. Unless you are communicating from script to script as to whether the cutscene is running or not, your script might be prematurely ending because the localscript firing the event has no idea as to whether the cutscene has finished or not. This script will need to know about it, so a bindable event might help

  2. You seem to clone a “FixCamera” script into the player’s CutsceneFolder (personally I’d put it under playerscripts but whatever works for you), you might want to check whether this is actively listening for a change in the camera, and whether it is responding to those changes or if it is only doing it once.

For troubleshooting, I would check whether the value being sent through the remote event is being changed each time. My final question to you is:

Are you still able to end the cutscene prematurely, and if so, are you able to start a new one right after without interruption?

If the answer to the above is yes, and the second answer is also a yes, then I would say that my 1st point (bullet point one) is likely whats causing the issue.

Feel free to get back to me if it isn’t!

3 Likes

Thanks for the elaboration! :stuck_out_tongue:

2 Likes

The reason i’m controlling everything from the Client Side is because the cutscenes are only to be activated by me during events. What do you mean by a Bindable Event? Do you mean,

  1. write up a bindable event that does this stuff and change all of this into stuff that calls the Bindable Event?
  2. Do you mean change this event to a Bindable event entirely?

Ah! I see why you need the server side element then. I was mostly under the pretense that it would be activated by anyone at any time, but the way you are doing it is totally fine.

I think one of the issues is that even if the cutscene finishes, it won’t clean itself up on the server side. Thus, when you call “Play”, it’ll think that players still have a cutscene playing, and will just try to remove the cutscene instead.

Try playing the cutscene 3 times in a row. If the cutscene doesn’t play the second time but plays the third time, thats the issue.

1 Like

That is impossible to do, I have it where if it detects the cutscene inside of the players PlayerGui Folder named Cutscenes that it will destroy it and fix their cameras. If you look at the entire script, the FixCam part is a script that I send to all players to fix their cameras. I control that manually as well.

If I click it once, it plays the cutscene, if I hit that same button MID the cutscene, it deletes the cutscene and fixes everyone’s cameras. If I hit it a third time, it will play the cutscene again.

So I just tried using a Bindable Event and it still does the exact same thing.
It plays the cutscene the first time around but if I let it go through the entire cutscene then try to play it again, it will instantly cut once it tries.

Your server side code does detect whether it exists when you press a button, however, as the cutscene script itself (the thing you are cloning into the players Cutscene Folder) is a localscript, if it tried to remove it self after finishing, the server would not recognize any difference, as on the server, it hasn’t been removed. This is the nature of Filtering Enabled, as it prevents the client from making changes like that unless a callback on the server has been setup to deal with it.

To fix this, you need to communicate to the server upon finishing the cutscene, so that it can remove it on the server, and not the client.

1 Like

That’s what I was able to figure out as it wasn’t able to register that the cutscene removed itself… what would you recommend to fix that?

In each of your cutscene scripts, chuck in a line at the end of the script that sends a message to a remote event, for example

CutsceneEvent:FireServer("cutsceneFinished",script.Name) -- uses script name to identify cutscene name

When this is sent over, the server then verifies this:

CutsceneEvent.OnServerEvent:connect(function(player,command,...)
local args = {...}
if command == "cutsceneFinished" then
local Input == args[1]
assert(type(Input) == "string","Cutscene Invalid - Not a String")
local cutscene = assert(player.PlayerGui.Cutscenes:FindFirstChild(Input),"Cutscene not Found")
cutscene:Destroy()
-- Cutscene Destroyed!
end
end)

This should help but if it doesn’t or something breaks, let me know!

2 Likes

Alright so I formatted it into my main script to link it with the rest of the camera scripts… its the bottom statement, i have the logal args above at the top.
when it tried to run lua cutscene:Destroy() it got a attempt to index local 'cutscene (a nil value)

Script

--Made By MillerrIAm
-------------------Variables------------------
Cutscene = game:GetService("ServerStorage").Cutscenes
FixCam = game:GetService("ServerStorage").ExtraItems
Event = game.ReplicatedStorage.GUIEvents.CutscenePlayer
------------------Main Script------------------
Event.OnServerEvent:Connect(function(plr,Play,argument)
	local args = {argument}
	if Play == "On" then
		for i,x in pairs (game.Players:GetPlayers()) do
			if x.PlayerGui.Cutscenes:FindFirstChild(""..argument) then
				x.PlayerGui.Cutscenes:ClearAllChildren()
				FixCam.FixCamera.Disabled = false
				FixCam.FixCamera:Clone().Parent = x.PlayerGui.Cutscenes
			else
				Cutscene:FindFirstChild(""..argument):Clone().Parent = x.PlayerGui.Cutscenes
				x.PlayerGui.Cutscenes:FindFirstChild(""..argument).Disabled = false
			end
		end
	elseif Play == "Off" then
		for i,x in pairs (game.Players:GetPlayers()) do
			x.PlayerGui.Cutscenes:ClearAllChildren()
			i = FixCam.FixCamera
			i.Disabled = false
			i:Clone().Parent = x.PlayerGui
		end
	elseif Play == "Finished" then
		local Input = args[1]
		assert(type(Input)== "string","Cutscene Invalid - Not a String")
		local cutscene assert(plr.PlayerGui.Cutscenes:FindFirstChild(Input), "Cutscene Not Found")
		cutscene:Destroy()
	end
end)

Everything here can and should be handled from the client. Don’t know why you’re using the server to access items in the PlayerGui. That’s bad practice. You should also look into a more event-based system over using the Disabled property.

The reason I have to use a PlayerGui is so no one else accesses these cutscenes nor activates them. I host events and some people host events in my place that are hosted by them. We control when the cutscenes play, when music plays, lighting changes, etc. It’s a little event that goes on for an hour and then the game shuts down. That is why I have to access it through the Server Side, with this… I’m using CloneTroopers Cutscene Maker/Editor to make cutscenes as I can’t seem to find much on the Cameras anywhere. CloneTroopers Cutscenes are automatically disabled and you have to re-enable them to make them work.

Long story short, I have the be the only one controlling them, no one else. That’s why.
Oh and Clonetroopers Cutscenes delete themselves after they complete.

This doesn’t say anything significant. You are still able to handle all of this properly through the client and should. You can easily have the server inform the client to do actions over controlling client-side elements from the server.

If you don’t want cutscenes being accessible or being activated, simply make it so they do not run without prompt from the server. Only ones who can bypass that are exploiters and them viewing cutscenes or whatever isn’t a significant enough reason to involve the server, as it’s nothing important that can cause damage.

Articles on Cameras are everywhere. It’s up to you to search, learn and apply the learning you get out of them towards creating systems, along with other API. For example, tweening cameras around points.

That is the problem, I have done everything I know how to plus I’ve also searched up everything on all ROBLOX sites about Cameras and how they work and there has been nothing useful for my issue.