Ey!
As of recent, I’ve been independently developing a puzzle-platformer game that utilizes the physics engine to create puzzles and contraptions. The game mechanics utilizes the very well-known btools to solve puzzles, alongside objects (i.e. Boxes), constraints, and platforms to complete puzzles. Now there is a lot more to this, but I don’t want to expose too much. Anyways, I’m trying to fix a “Respawn” system I created. Let me explain;
In the puzzles, if you accidentally mess up during a puzzle that utilizes a box for example to continue going forward. You can click on a part button (not a GUI interface), and it will teleport/“respawning”, right next to the button. I also have it set up that if the box doesn’t exist, say that a player accidentally deletes it. Not to worry because it will make a new copy of that object.
Before we get into issues and hopefully you understand everything, you should learn how this works inside Roblox Studio, and it is pretty simple; there are two scripts located in ServerScriptStorage
named OnClickIFWorkspace
and OnClickIFnil
.
-
OnClickIFWorkspace
responsibility is to find the said object inWorkspace
; if it finds the object, it will teleport it based on the coordinates provided in the script. -
OnClickIFnil
responsibility is to see if the object doesn’t exist, which if it doesn’t will create a new copy of the said object fromReplicatedStorage
and put the clone inWorkspace
based on the coordinates provided in the script.
These two scripts are running at the same time, and are fired when the ClickDetector function is fired from clicking on RespawnBox1
which causes Box2
to teleport from the said coordinates in Workspace
.
Here I will provide the code for both scripts:
OnClickIFWorkspace
:
local FindBox = game.Workspace:FindFirstChild("Box2")
local Box = game.Workspace.Box2
function onClicked()
if FindBox then
Box.Position = Vector3.new(0, 4, 0)
Box.Orientation = Vector3.new(0,0,0)
if Box.Position == Vector3.new(0, 4, 0) and Box.Orientation == Vector3.new(0,0,0) then
print("Objective Successful!")
end
end
end
OnClickIFnil
:
local FindBox = game.Workspace:FindFirstChild("Box2")
local Box = game.Workspace.Box2
local StoredBox = game.ReplicatedStorage.Box2
function onClicked()
if FindBox == nil then
local ClonedBox = StoredBox:Clone()
print("Was not able to detect Box in Workspace! Cloning from ReplicatedStorage...")
ClonedBox.Parent = game.Workspace
if ClonedBox.Parent == game.Workspace then
Box.Position = Vector3.new(0, 4, 0)
Box.Orientation = Vector3.new(0,0,0)
if Box.Position == Vector3.new(0, 4, 0) and Box.Orientation == Vector3.new(0,0,0) then
print("Cloning Successful!")
end
end
end
end
game.Workspace.RespawnBox1.ClickDetector.MouseClick:connect(onClicked)
This is where we get into issues now. Remember when I said that if the box doesn’t exist, it will make a new copy? For some reason, it doesn’t create a new copy in the client, but when we look at the server, it cloned.
Because the script still cloned the object into Workspace, there really shouldn’t be anything wrong as far as I’m aware. It could be something on Roblox’s end, but that can be argued by this error message:
I still do not understand a lot of the problem, and the fact that I am a beginner programmer makes it somewhat more of a challenge but fun. I tried to resolve my issue by searching on Google and searching the Developer Forum. It did not help.