I am trying to make a Roblox game where the user presses a cat and a random event happens, here in this event I wanted a part in the replicated storage to be cloned then parented to the workspace. but something is wrong and it gives me an error of "unexpected identifier when phrasing an expression"
oh by the way the only thing underlined is the "=" after the .parent
here is the code:
Blockquote
--variables
local Rep_storage = game:GetService("ReplicatedStorage")
local Cat = workspace["Cat button"].cat
local num_of_events = 1 --change depending on number of events
--main function
Cat.ClickDetector.MouseClick:Connect(function()
if Cat.ClickDetector.Clickable.Value == true then
local Rand_event = math.random(1,num_of_events)
--events
if Rand_event == 1 then
local lava_cat = Rep_storage["event items"]["lava cat"]
local clone = lava_cat:Clone().Parent = workspace
end
end
end)
"Unexpected identifier when parsing expression" means that you have written syntactically invalid code.
On this line :
local clone = lava_cat:Clone().Parent = workspace
The issue is that you cannot set equality twice on a single line. You can initialize the local clone
variable, or you can set the .Parent
property. You cannot do both at the same time.
The fix is simple, just break this line into two :
local clone = lava_cat:Clone()
clone.Parent = workspace
-- or don't bother creating a variable
-- lava_cat:Clone().Parent = workspace