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:
Please let me know if you need more information.