Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago
Edited 4 years ago

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 <string>, got 'and'

1 answer

Log in to vote
0
Answered by
blazar04 281 Moderation Voter
4 years ago

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!

0
Thank you! WizardEpidemic 11 — 4y
0
No problem! It would be great if you could mark my response as the answer! blazar04 281 — 4y
0
WizardEpidemic, click "Accept Answer" below ItzFoxz's answer. DesertusX 435 — 4y
0
Oh, thank you I didn't know WizardEpidemic 11 — 4y
Ad

Answer this question