Code not even printing when attempting to get text of a TextButton

Hello! I am working on a game called “chess playground”. You can have a look at it here: chess playground - Roblox


Anyways, I was working on an upright button, so that when you place a piece you can choose if you want it to always be upright or it is able to fall. While I was doing the scripts, I tried it and it wasn’t working.


I then added a print() in the scripts to see if it was detecting it, but it somehow skipped a print???
I was really confused, and that is the reason I am creating this topic.


It uses a LocalScript, a RemoteEvent, and a Script. Here are the contents:
LocalScript (parented to a TextButton):

	local Colour = script.Parent.Parent.Toggle.Text
	local Piece = script.Parent.Parent.PieceBox.Text
	if game.ReplicatedStorage:FindFirstChild(Colour) then
		if game.ReplicatedStorage:FindFirstChild(Colour):FindFirstChild(Piece) then
			script["Wood Hits Wood 2 (SFX)"]:Play()
			game.ReplicatedStorage.PieceEvent:FireServer(game.ReplicatedStorage:FindFirstChild(Colour),game.ReplicatedStorage:FindFirstChild(Colour):FindFirstChild(Piece))
		end
	end
end)
game:GetService("UserInputService").InputBegan:Connect(function(inp,gpe)
	if gpe then return end
	if inp.KeyCode == Enum.KeyCode.E or inp.KeyCode == Enum.KeyCode.ButtonL2 then
		local Colour = script.Parent.Parent.Toggle.Text
		local Piece = script.Parent.Parent.PieceBox.Text
		if game.ReplicatedStorage:FindFirstChild(Colour) then
			if game.ReplicatedStorage:FindFirstChild(Colour):FindFirstChild(Piece) then
				script["Wood Hits Wood 2 (SFX)"]:Play()
				print(game.Players.LocalPlayer.PlayerGui.ScreenGui.UprightToggle.Text) -- not printing for some reason

				game.ReplicatedStorage.PieceEvent:FireServer(game.ReplicatedStorage:FindFirstChild(Colour),game.ReplicatedStorage:FindFirstChild(Colour):FindFirstChild(Piece), game.Players.LocalPlayer.PlayerGui.ScreenGui.UprightToggle.Text)
			end
		end
	end
end)

Script (in ServerScriptService);

game.ReplicatedStorage.PieceEvent.OnServerEvent:Connect(function(plr,colour,piece:MeshPart, text:string)
	local char = plr.Character
	local pieceC = piece:Clone()
	pieceC.Parent = workspace.Pieces
	local root : Part = char.HumanoidRootPart
	pieceC.Position = root.Position + root.CFrame.LookVector * 4
	pieceC.Orientation = root.Orientation
	if text == "Upright Enabled" then
		print("upright") -- not printing
		local upright = game.ReplicatedStorage.UprightScript:Clone()
		upright.Parent = pieceC
		upright.Enabled = true
	end
end)

Here is the ancestry of important instances:
image


image


Please let me know if you need more information.

bump bump bump bump bump bump bump bump

bumping again pls i need help idk what to do

isn’t the local script parented to the text button? why do you need to go through PlayerGui?

Hello, i’ve analysed your scripts, aswell as their corresponding ancestry and i still don’t know the problem,

can you please lmk the descendants of

Black & white

and the texts of

Toggle, PieceBox, UprightToggle aswell as the rest

The only reason I could think of the print statements not working is if the if statements didn’t run I think you need to look into those if statements

u’ve got a point

HBFJKF

especially the

if text == “Upright Enabled” then

and

if game.ReplicatedStorage:FindFirstChild(Colour):FindFirstChild(Piece) then

I BEG YOU make some variables for them please

Descendants of Black and White:
image

Texts:
CleanupVote - Vote Cleanup x/y
PieceBox - Default “Pawn”, but cycles through Pawn,Knight,Bishop,Rook,Queen and King when clicked.
Spawn - “Spawn!”
Toggle - Default “White”, but alternates between White and Black when clicked.
UprightToggle - Default “Upright Disabled”, but alternates between “Upright Disabled” and “Upright Enbaled” when clicked.

I hope this helps.

Oh yeah, and in the local script the two lines of code in the same if statement as the print(game.Players.LocalPlayer.PlayerGui.ScreenGui.UprightToggle.Text) run normally, so that just confuses me even more.

Wait am I wrong or are the arguments for UserInputService wrong? Don’t they need to be flipped

No, i checked and they’re the right way around.

b
u
m
p

i

n
e
e
d

t
h
i
s

f
i
x
e
d

bumping, need some help, cant update my game

I just figured it out, and its the stupidest problem. It only executes when you use the E keybind because i didnt put the things in the activated listener and i kept testing by clicking the button.

At least its fixed now.

:sob:

This text was blurred