Check if Enabled or not

Hi guys! So I made a script, if the player joins to the game they cant move, because the HumanoidRootPart is anchored by a local script in StarterPlayerScripts. All I want is to check if the player is pressed on the Play button, and if its true, the HumanoidRootPart.Anchored = false.

Heres the codes, and the structure of the objects:

image

StarterPlayer → StarterPlayerScripts → LocalScript:

local player = game.Players.LocalPlayer
local letsMove = game.StarterGui.TeamGui.Enabled

player.CharacterAdded:Connect(function(character)
	character:WaitForChild("HumanoidRootPart").Anchored = true
	if letsMove == false then
		character:WaitForChild("HumanoidRootPart").Anchored = false
	end
end)

And for the main menu screen this is the structure for it:
image

StarterGui → TeamGui → Background → PlayAsARed → teamTeleporterScript:

local p = script.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	p.Team = game:GetService("Teams").Red
	p:LoadCharacter()
	
	wait(3)
	script.Parent.Parent.Parent.Enabled = false
end)

Thanks! Bye! :slight_smile:

1 Like

Do you mean something like if HumanoidRootPart.Anchored then?

As I said, if the player joins to the game they cant move, because they’re on the Main Menu screen, and the movement is disabled by just a script, where the HumanoidRootPart is anchored. And what I want:

A script which checks, if the player pressed on the Play button. And if the player pressed the play button, then the HumanoidRootPart is not anchored anymore for him.

Like this?

Button.MouseButton1Click:Connect(function()
	character:WaitForChild("HumanoidRootPart").Anchored = false
end)

It doesnt work too :confused:

I put this script to:
image

And heres whats inside of teamTeleporterScript:

local p = script.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	p.Team = game:GetService("Teams").Red
	p:LoadCharacter()
	
	wait(3)
	script.Parent.Parent.Parent.Enabled = false
	p:WaitForChild("HumanoidRootPart").Anchored = false -- This
end)

It has to be in a LocalScript to detect the button press, if you want to send it to a ServerScript then use a RemoteEvent.

And how can I do this? Im actually new to scripting

You can do this on a UI:

-- You can do as much as possible, so i'm doing 1 Parent because if you want to make the script touching the screengui the it's on the 2nd line.
script.Parent.Enabled = false -- You can do true...

if not script.Parent.Enabled == true then
	while task.wait(0.02) do
		warn("The Gui isn't visible")
	end
end

if not script.Parent.Enabled == false then
	print("The Gui is visible")
end

Okay, done.

I’m not the best at explaining, but I’ll try my best.
You want to start by adding a “RemoteEvent” in ReplicatedStorage. Name it whatever you want.
Then, use this code in a LocalScript inside of the start button:

script.Parent.MouseButton1Click:Connect(function()
    game.ReplicatedStorage.RemoteEvent:FireServer() -- Replace RemoteEvent with you RemoteEvent's name
end)

This sends a message through the RemoteEvent to the server. Now we have to pick it up with the server.

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(plr) -- When firing a RemoteEvent from a client, the first variable (I'm calling it "plr") is the player that sent the event
    plr.Character:WaitForChild("HumanoidRootPart").Anchored = false
end)

I think that the problem is in line 2. You should be doing:

local letsMove = game.StarterGui.TeamGui

And when you want to check if it is enabled or not:

if letsMove.Enabled == false then

Hope this helped