Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

ANSWEREDWorkspace.Part.script:13: Expected '(', '{' or <string>, got 'and' --- How do I fix it?

I am very very new to coding, I tried to modify a spawning car button. I'm attempting to make it so that when you step on the block it creates a car and if you already have a car as your child, then it is removed and instead spawns a new car as your child. In other words it just respawns the car. Testing with Play Mode. This is a server-side script

script.Parent.Touched:connect(function(GetCar)
	local character = GetCar.Parent

	local humanoid = character:FindFirstChildWhichIsA("Humanoid")
	if humanoid then
		local Mod = game.ServerStorage.car
		local clone = Mod:clone()
		clone.Parent = workspace
		clone:MakeJoints()
			elseif humanoid.child == game.ServerStorage.car
			then
				humanoid.child:remove
				and
				 while true do humanoid then
					local Mod = game.ServerStorage.car
					local clone = Mod:clone()
					clone.Parent = workspace
					clone:MakeJoints()
			end
		end
	end
end)

The error I get is this: Workspace.Part.script:13: Expected '(', '{' or , got 'and'

1 answer

✓ Accepted answer

So the error is that you did not add the parenthesis after humanoid.child:remove (should be humanoid.child:remove(), but that is not really the issue here. First of all, the car's parent is not the humanoid, but ServerStorage, therefore car is not a child of the humanoid. Just to clarify, a child of an object is and object that is positioned below a certain parent object in the hierarchy. So for instance if you created a Model in the workspace and had multiple parts inside of the model, then the parts are a child of the model, and the model is a parent of the parts. Also, the workspace would be a parent of the model.

Also I would suggest you look into tutorials for if statements and loops, as it seems you may not have a full understanding yet.

In terms of your script here is what I think you should do:

-- When the parent of the script is touched
script.Parent.Touched:connect(function(GetCar)
	-- Find car in workspace
	local car = workspace:FindFirstChild("car")
	
	-- If we successfully found the car, then destroy it
	if car then
		car:Destroy()
	end
       
	-- Get the new car in ServerStorage and clone it
	local clone = game.ServerStorage.car:clone()

	-- Parent the car in workspace
	clone.Parent = workspace
	
	clone:MakeJoints()
end)

Programming is a skill that will take you far in life, and it is great that you are getting started. It isn't easy, but the challenge is what makes it fun. Keep practicing, and have fun!

4 comments

0

Thank you!

0

No problem! It would be great if you could mark my response as the answer!

0

WizardEpidemic, click "Accept Answer" below ItzFoxz's answer.

0

Oh, thank you I didn't know

This discussion is preserved as it was. New answers, comments, and votes are closed.