System works once, does not afterwards

Hi, so I have a Job System that fires an event to communicate with the client that your shift began, and it should print a message saying “Began Job”. As expected, it works the first time however it doesn’t afterwards at all. I can’t find a solution to this issue, and there are no errors in the output. Any help trying to debug this is appreciated

Video

Server:

script.Parent.Prompt.Triggered:Connect(function(player)
	print("Triggered")
	wait(.1)
	game.ReplicatedStorage.JobSystem.StartJob:FireClient(player)
	script.Parent.Parent.Shift.Value = true
	script.Parent.Prompt.Enabled = false
	script.Parent.Job.Enabled = true
	local clone = script.Parent.Job:Clone()
	clone.Parent = player.PlayerGui
	script.Parent.WalkSpeed.Value = player.Character.Humanoid.WalkSpeed -- Saves current speed so doesnt reset
	script.Parent.JumpPower.Value = player.Character.Humanoid.JumpPower
	stop(player)
	local x = script.Parent.Parent.WorkPlace.Position.X
	local y = script.Parent.Parent.WorkPlace.Position.Y
	local z = script.Parent.Parent.WorkPlace.Position.Z
	player.Character.HumanoidRootPart.CFrame = CFrame.new(x,y+2,z) --Teleports player to their work space
end) 

Client:

function spawnai()
	game.ReplicatedStorage.JobSystem.SpawnAI:FireServer()
	script.Parent.Order.Visible = true
end

game.ReplicatedStorage.JobSystem.StartJob.OnClientEvent:Connect(function(player)
	spawnai()
	print("Began Job")
end)

playerGui changes should be done in a local script

1 Like

show meh the end shift gui button script ty

1 Like

The way i see the problem is that your trying to do things to the client inside of a server script. Assuming that you want the client to only see the job etc etc so you would wanna do this in a local script. Try moving all the actions to the local script inside of the on client even function. Example Below

Server Script:

script.Parent.Prompt.Triggered:Connect(function(player)
	print("Triggered")
	wait(.1)
	game.ReplicatedStorage.JobSystem.StartJob:FireClient(player)
end) 

Local Script:

function spawnai()
	game.ReplicatedStorage.JobSystem.SpawnAI:FireServer()
	script.Parent.Order.Visible = true
end

game.ReplicatedStorage.JobSystem.StartJob.OnClientEvent:Connect(function(player)
	spawnai()
	script.Parent.Parent.Shift.Value = true
	script.Parent.Prompt.Enabled = false
	script.Parent.Job.Enabled = true
	local clone = script.Parent.Job:Clone()
	clone.Parent = player.PlayerGui
	script.Parent.WalkSpeed.Value = player.Character.Humanoid.WalkSpeed -- Saves current speed so doesnt reset
	script.Parent.JumpPower.Value = player.Character.Humanoid.JumpPower
	stop(player)
	local x = script.Parent.Parent.WorkPlace.Position.X
	local y = script.Parent.Parent.WorkPlace.Position.Y
	local z = script.Parent.Parent.WorkPlace.Position.Z
	player.Character.HumanoidRootPart.CFrame = CFrame.new(x,y+2,z) --Teleports player to their work space
	print("Began Job")
end)

Im not in studio so i have 0 clue if this works or not, just test it out and give me feedback. i am on the dev forum daily and i check all my notifications so ill reply fast!

1 Like

Sorry for late replies!

game.ReplicatedStorage.JobSystem.EndShift.OnClientEvent:Connect(function()
	script.Parent.Order.Visible = false
	script.Parent.End.Visible = false
	script.Parent.Black:TweenSizeAndPosition(UDim2.new(0, 2000,0, 800),UDim2.new(0.5,0,0.5,0),Enum.EasingDirection.Out,Enum.EasingStyle.Linear,.5)
	wait(1)
	game.ReplicatedStorage.JobSystem.EndShift:FireServer()
	script.Parent.Black:TweenSizeAndPosition(UDim2.new(0, 0,0, 800),UDim2.new(-0,0,0.5,0),Enum.EasingDirection.Out,Enum.EasingStyle.Linear,.5)
	wait(.5)
	script.Parent:Destroy()
end)

All of your solutions are great, I switched playergui changes to be in a client, but my issue is still occuring. I think it’s still something wrong, but now it does not run the local script at all. The GUI is enabled and I still can’t find what it is from preventing the OnClientEvent function from happening.

dont destroy it and try to see if it works if u want it to not be visible just set it to false

1 Like

Yeah, I tried that already and it doesn’t seem to work.

You can make a remote event to locally open the GUI. GUI scripting is ALWAYS done with the PlayerGui. Otherwise, it won’t work again later.

function spawnai()
	game.ReplicatedStorage.JobSystem.SpawnAI:FireServer()
	-- game.ReplicatedStorage.OpenGui:FireClient()
end

Afterward, create a LocalScript in the frame and write this:

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

game.ReplicatedStorage.OpenGui.OnClientEvent:Connect(function()
- Frame -.Visible = true
end)
1 Like

Thank you! I will be using local scripts to work with playergui’s from now on.