respawntime = 10 brick = script.Parent clone = brick:Clone() position = brick.Position brick.Changed:connect(function() local newposition = brick.Position if position ~= newposition then wait(respawntime) brick:Destroy() clone.Parent = game.Workspace clone.Position = position end end end)
Error from Roblox Studio: Script:5: unexpected symbol near ')'
Hey there! BlackOrange here to help! (Check bottom .Changed actually works)
First of all, if Brick
is a Part
, I believe that you can't use .Changed
on it. .Changed
is normally for values such as IntValue
, StringValue
, NumberValue
, ObjectValue
and so on. So you might wanna change that part up.
Next, your code is very messy, so let's start off by making sure this is a ServerScript
also known as Script
Now, Let's change your variables to local variables
because right now you don't need global variables
.
local respawntime = 10 local brick = script.Parent local clone = brick:Clone() local position = brick.Position brick.Changed:connect(function() local newposition = brick.Position if position ~= newposition then wait(respawntime) brick:Destroy() clone.Parent = game.Workspace clone.Position = position end end end)
Alright! But wait, the error says... Roblox Studio: Script:5: unexpected symbol near ')'
Let's check out code. Most likely you have added an extra end!
local respawntime = 10 local brick = script.Parent local clone = brick:Clone() local position = brick.Position brick.Changed:connect(function() -- This creates 1 end) local newposition = brick.Position if position ~= newposition then -- this creates 1 end wait(respawntime) brick:Destroy() clone.Parent = game.Workspace clone.Position = position end -- you have extra end! end end)
Alright, now delete the end so now we can move on. We now have to see what other problems are there. Firstly, when setting a position of a part, we use Vector3
or CFrame
Let's use Vector3
local respawntime = 10 local brick = script.Parent local clone = brick:Clone() local position = brick.Position brick.Changed:Connect(function(p) -- This creates 1 end) local newposition = brick.Position if p == "Position" then -- this creates 1 end wait(respawntime) brick:Destroy() clone.Parent = game.Workspace clone.Position = Vector3.new(position) -- stores x,y,z end end)
Alright almost done! ok now add p
stands for property and check if property changed and change :connect
to :Connect
because :connect
is deprecated. If you fix p
everything should work out!
Links that might help you out: http://wiki.roblox.com/index.php?title=API:Vector3 http://wiki.roblox.com/index.php/CFrame http://wiki.roblox.com/index.php?title=API:Class/Instance/Changed -- Actually never mind, I just read it and it fires when any value changes sorry! https://wiki.roblox.com/index.php?title=Changed https://wiki.roblox.com/index.php?title=Deprecation
Best of luck my friend! Final code is the last one
You have made a syntax error in your script. The method you’re using is also not so good; you should check if the property that changed is the position, otherwise you’re checking it needlessly.
local respawntime = 10 local brick = script.Parent local position = brick.Position brick.Changed:connect(function(property) if property == "Position" then wait(respawntime) brick:Destroy() local clone = brick:Clone() clone.Parent = game.Workspace clone.Position = position end end)