Help change players gui script form server script

Hello, I’m trying to make it where my monsters ai footsteps change based on the speed of it, in the ai is a server script that checks the speed of the ai but how would I access the players gui from a server script? Inside player gui is a script that makes your screen shake, I want it where when the speed of the ai is 16 then the walk screen shake disabled and the run shake enables so how do I access that?

1 Like

Try this, it loops through all the players and gets the player gui.

local Players = game:GetService("Players")

for _, Player in pairs(Players:GetChildren()) do
	local PlayerGui = Player.PlayerGui or Player:WaitForChild("PlayerGui")
	
	local Ui = PlayerGui.[YourUi]
end

Would I have to put that script but including variable everytime I want to use player?

Could you specify which variable? you’ll have to do the for-loop, but the player should only be defined once

	    if Speed < 1 then  -- if its anything smaller than that Number
		Run:Play()
		script.Parent.HumanoidRootPart.footstep01.PlaybackSpeed = 0.3
	else
		if Speed < 20 then -- if its anything smaller than that Number
			script.Parent.HumanoidRootPart.footstep01.PlaybackSpeed = 0.7
		else
			script.Parent.HumanoidRootPart.footstep01.PlaybackSpeed = 1
		end
	end
end)

i want if the speed is < 20 then ShakingRun Enables, i would do it to every speed function here

btw ShakingRun is a script in player gui

You’ll need to trigger the local script, correct? if so try using a remote event instead

I tried that but I failed pretty bad, I did this Event:FireAllClients(Player, True)

local Folder = ReplicatedStorage:WaitForChild("Remotes")
local RunEvent = Folder:WaitForChild("ChangeToRun")
local WalkEvent = Folder:WaitForChild("ChangeToWalk")
local IdleEvent = Folder:WaitForChild("ChangeToStuck")
local Player = game:GetService("Players")

RunEvent.OnClientEvent:Connect(function()
while wait(timeBetween) do
	if (monster.HumanoidRootPart.Position - char.HumanoidRootPart.Position).Magnitude <= 300 then
		local mag = (monster.HumanoidRootPart.Position - char.HumanoidRootPart.Position).Magnitude
		if mag < 80 then
			camShake:ShakeOnce(20,20,0.25,0.25)
		elseif mag < 130 then
			camShake:ShakeOnce(10,10,0.25,0.25)
		elseif mag < 230 then
			camShake:ShakeOnce(4,4,0.25,0.25)
		else
				camShake:ShakeOnce(2,2,0.25,0.25)
			end
		end
	end
end)
	    if Speed < 1 then  -- if its anything smaller than that Number
		Run:Play()
		script.Parent.HumanoidRootPart.footstep01.PlaybackSpeed = 0.3
		IdleEvent:FireAllClients(Player, true)
		WalkEvent:FireAllClients(Player, false)
		RunEvent:FireAllClients(Player, false)
	else
		if Speed < 20 then -- if its anything smaller than that Number
			script.Parent.HumanoidRootPart.footstep01.PlaybackSpeed = 0.7
			IdleEvent:FireAllClients(Player, false)
			WalkEvent:FireAllClients(Player, true)
			RunEvent:FireAllClients(Player, false)
		else
			script.Parent.HumanoidRootPart.footstep01.PlaybackSpeed = 1
			IdleEvent:FireAllClients(Player, false)
			WalkEvent:FireAllClients(Player, false)
			RunEvent:FireAllClients(Player, true)
		end
	end
end)

Did that and it Dident work it glitched very badly and made it shake like crazy

I don’t use remote events but I thought saying true would idk make it true and if it’s false it wouldn’t work until true

1 Like

Idk if u were talking about what I said

1 Like

if you want it so that when its true the shake starts and false shake stops, you’ll have to set the data in the local script. RunEvent.OnServerEvent:Connect(function(value) – the value is the true/ false you sent

Then you can set another if statement, if true then start shake, if false then stop or something like that

Only thing I’m confused about is the value part

So I would still do Event:FireAllClient(Player,True)?

1 Like

Aight so would I still do (Player, True) or no

I forgot one thing, when using the :FireAllClients the player isn’t needed just send the value directly RunEvent:FireAllClients(value – true/false)

You shouldn’t handle any player’s PlayerGui instance from a server script (even though it’s possible), Gui manipulation should be handled by the locally on the client-side only through the use of local scripts, to achieve this you could simply loop through all players inside a server script and fire each individual client through a call to “FireClient()” through a RemoteEvent instance, alternatively you can also call “FireAllClients()” through a RemoteEvent instance without needing to loop through all of the players beforehand.