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

FireAllClients not working when GUI pressed?

I have changed the script around and to make it easier to understand I will put all the script and describe the GUI parts and where the Remote Events are held.

The ScreenGui is called "CamOnDev" and contains a "Frame" in it. In that frame it contains 2 text boxes, "Enable" and "Disable", a TextBox called "pname" and a text label that doesnt appear in the scripts, The screen gui is in Replicated Storage and a script in ServerScriptService controls what players get the gui, The script is pasted below.

GUI Giver: (Script)

game.Players.PlayerAdded:Connect(function(plr)
	if plr.Name == "Eletrinn" then
		local gui = game.ReplicatedStorage["CamOnDev"]:Clone()
		gui.Parent = plr.PlayerGui
	end
end)

The Remote Events called "CamAll" and "DisableCamAll" is also held in ReplicatedStorage. The script that controls these are in ServerScriptService and the code is pasted below

Remote Event Script: (Script)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local CamAll = ReplicatedStorage:WaitForChild("CamAll")
local DisableCamAll = ReplicatedStorage:WaitForChild("DisableCamAll")
local gui = game.Players:WaitForChild("Eletrinn").PlayerGui.CamOnDev.Frame

gui.Enable.MouseButton1Click:Connect(function()
	CamAll:FireAllClients()
end)

gui.Disable.MouseButton1Click:Connect(function()
	DisableCamAll:FireAllClients()
end)

The Final scripts are located in StarterPlayerScripts and have the "Enable" script, for the enable button in the gui and the "Disable" script for the disable button in the gui. Both scripts are pasted below.

Enable script: (Local Script)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DisableCamAll = ReplicatedStorage:WaitForChild("DisableCamAll")
local CamAll = ReplicatedStorage:WaitForChild("CamAll")
local cam = workspace.CurrentCamera
local CamPart = game.Workspace.CamPart
Disable = true

DisableCamAll.OnClientEvent:Connect(function()
	Disable = false
end)

CamAll.OnClientEvent:Connect(function()
	Disable = true
	local gui = game.Players:WaitForChild("Eletrinn").PlayerGui.CamOnDev.Frame
	local FocusPart = game.Workspace:WaitForChild(gui.pname.Text).UpperTorso
	print("Cam Enabled.")
	while Disable == true do
		cam.CameraType = Enum.CameraType.Scriptable
		cam:Interpolate(CamPart.CFrame, FocusPart.CFrame, 0.5)
		gui.Enable.Visible = false
		gui.Disable.Visible = true
		wait(0.2)
	end
end)

Disable script: (Local Script)

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DisableCamAll = ReplicatedStorage:WaitForChild("DisableCamAll")
local cam = workspace.CurrentCamera

DisableCamAll.OnClientEvent:Connect(function()
	local gui = game.Players:WaitForChild("Eletrinn").PlayerGui.CamOnDev.Frame
	print("Cam Disabled.")
	cam.CameraType = "Custom"
	gui.Disable.Visible = false
	gui.Enable.Visible = true
end)

What happens is when I type in the name of the player in the gui TextBox it finds that players Upper Torso and should put everyone in the servers cameras looking towards the players upper torso from the "CamPart" which is just a part in the workspace. But what happened is I joined with my main account and my alt on the roblox app, and typed in the name of the player I want focused on and clicked the enable button but it only affected my camera and not anyone else's. I hope that is enough information to help solve the issue I am having and I hope to hear from you soon.

2 comments

0

This can be cause by changing GUI in server

0

How do I fix this?

1 answer

✓ Accepted answer

Whatever Gui you manipulate on your client, the changes won't replicate to the server nor to other clients. In your Enable script, when the event is fired, it'll attempt to get the text you inputted in your textbox, but the other clients won't see what you just inputted into the textbox, but you will because it's on your own client.

It is advised that you do Gui manipulation on the player's own client instead of the server because changes won't replicate to the server if you manipulate guis on your client. What you would want to do is use one, whole RemoteEvent instead of multiple so that you don't have to make so much

You would need to handle the MouseButton1Click events in a local script and when fired, it should fire to the server with the current text in the TextBox:

local RE = -- RemoteEvent
gui.Enable.MouseButton1Click:Connect(function()
	RE:FireServer(gui.pname.Text)
end)

On the server, you'll fire to all clients with the passed text:

RE.OnServerEvent:Connect(function(player, text)
	RE:FireAllClients(text)
end)

When the player receives the event on the client, you can do the same thing:

RE.OnClientEvent:Connect(function(txt)
	-- interpolate camera
end)

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