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

Why is it asking about a name near it?

Asked by 9 years ago

mmk so I just started learning how to script. I wanted to make a part named Brick, clone you when you step on it. I made this little script but it keeps saying there's an error and want a name near it or something. Any help?

bool = true
ping = game.Workspace.Player

function
    if bool == false then return end
    bool = false
    ping:clone().parent = Workspace
    wait(4)
    bool = true
end

ping.Touched:connect(clonePlayer)

3 answers

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

functions have two forms:

definitions -- where you give a name (and it's a statement):

function myFunc()
    -- stuff
end

anonymous -- where you don't give a name (and it's an expression):

blah = function()

end

Your code looks like neither -- you don't have anything after the function keyword and you at least need ().

The error is telling you expecting a name because it's assuming you mean the first kind of function:

function clonePlayer()
    if bool == false then return end
    ..... -- etc
end

You have to use .Parent and not .parent. Names are case-sensitive.

bool is a terrible variable name. Describe what it means! e.g., maybe cloned. Then cloned starts as nil or false and you can say

if cloned then return end
cloned = true
0
I was going off the myBool thing of true or false. Bool meaning if the script was false it would go straight to the end. If it was true it would keep going. But I didn't know about the case sensitive stuff, thanks! :) VirtualFlying 55 — 9y
0
You want your variable names to have meaning. Yes, it's a boolean, but that doesn't tell you anything about what it's for. BlueTaslem 18071 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

Ahh! I fixed it!

ding = true
ping = game.Workspace.Player

function clonePlayer()
    if ding == false then return end
    ding = false
    ping:clone().Parent = Workspace
    wait(4)
    ding = true
end

ping.Touched:connect(clonePlayer)

First I changed the Bool to Ding for a better name I guess. But the name was missing after the function! I forgot clonePlayer()!! Looking at my Lua Learning Book on Amazon and saw I missed it. Thanks guys! I didn't know ROBLOX was case sensitive. :)

Log in to vote
-1
Answered by 9 years ago

Your syntax is a but messed up in the middle try something like this

local newPart = ping:Clone()
newPart.Parent = game.Workspace
0
I wanted to make it clone your character. It was named Player in test mode. I'll change some wording and get back to you. VirtualFlying 55 — 9y
0
if you want to clone the character then that script would look much different ProfessorSev 220 — 9y
0
This is not necessary. What he had is perfectly acceptable in syntax. He should just use .Parent instead of .parent. BlueTaslem 18071 — 9y

Answer this question