Won't Enable Script

I am making a script where if you click on a UI button then the bool value will change. Since you can’t change the bool value client sided I did it so that if the button was clicked (detecting with a local script) it will make the server script enabled which would change the value. The problem is the local script is not enabling the server script.

Code:

– Server

while task.wait() do
	if script.Enabled == true then
		game.StarterGui.MenuScreen.PlayPressed.Value = true
	end
end

– Client

script.Parent.MouseButton1Click:Connect(function()
	print("clicked")
	script.Script2.Enabled = true
	task.wait(2)
	script.Enabled = false
end)

I dont think you can enable Server Scripts via LocalScript, Server Scripts only fire for the Server while LocalScripts fire for the Client, try using a RemoteEvent

Do you know how I can change the code for it to work?

RemoteEvent.OnServerEvent:Connect(function(plr, Script, Status)
    print("clicked")
	Script.Enabled = Status -- true or false
	task.wait(2)
	Script.Enabled = false
end)
script.Parent.MouseButton1Click:Connect(function()
    RemoteEvent:FireServer(script.Script2, true) -- Fires to Server
end)

Can you explain the code please?

Script is the Script you want to change
Status is the Boolean

Script.Enabled = Status sets the Status of the Boolean
2 Seconds later, it disables the Script

Should I do

local Status = (the bool value)

i dont think so, you can just put Script.Enabled = Status and then apply the Boolean after

I am so confused right now on the code my brain is fried.

I dont know what is Cairo trying to do but that code is wrong, your Code also makes no sense to me.

Create a RemoteEvent and put it in ReplicatedStorage.

Client:

local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

script.Parent.MouseButton1Click:Connect(function()
	print("Clicked")

remoteEvent:FireServer()

end)

Server:

local remoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent")

remoteEvent.OnServerEvent:Connect(function(player)

game.StarterGui.MenuScreen.PlayPressed.Value = true

end)

You can change the BoolValue via Client but it will just be Visible for you. Changing the BoolValue from the Server, like we do in the Script i gave u will change it for all Players in the Game. You cant change a Server owned Instance from the Client, it would change just for you, not for others, that also means you cant enable a Server Script from the Client.

You wrote game.StarterGui.MenuScreen.PlayPressed.Value = true, that will do nothing, the StarterGui will copy its Instances to the PlayerGui, the StarterGui does just exist in your Studio(Not sure but its not existing for the Player itself).

You are using a ServerScript to change a Value what is inside the Client on a MenuScreen, you dont need to use Server if you just want to make it Visible for you, if you want to use Server then there are other better ways.

1 Like

script.Parent.MouseButton1Down:Connect(function()
script.Parent.Parent.Parent.Parent.Parent.Parent.Enabled.Value = true
end)

– Local

script.Parent.MouseButton1Down:Connect(function()
script.Parent.Parent.Parent.Parent.Parent.Parent.Enabled.Value = true
end)

I thought you can only fire a remote event for on the server? I’ll try this when I’m on my laptop.

The point was;

When the player joins there is a cutscene menu, when the play button is pressed it will make the PlayPressed value true and then the cutscene will end. I only want everything to be for the client so the value would change only for the person who pressed play

RemoteEvent is for both, Server and Client.

Then you just need this to make the Value change for you:

Client:

local playPressed = "Where your Value located at, Example: script.Parent.Parent:WaitForChild("PlayPressed")"

script.Parent.MouseButton1Click:Connect(function()
	print("Clicked")

playPressed.Value = true

end)