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

How to fix the error "'end' expected (to close 'function' at line 5) near '<eof>'" in this script?

So, I am trying to fix this script and I'm getting the error listed above. I've looked at other answers but can't seem to figure out how to fix it! If you can help me out and tell me what's wrong and how to fix it that would be great.

Script:

local model = script.Parent

local j = game.Workspace.Test.Part1

local k = game.Workspace.Test.Part

local function onModelTouched(part)

if part:IsDescendantOf(model) then return end

local user = game.Players:GetPlayerFromCharacter(hit.Parent)

local stats = user:findFirstChild("leaderstats")

if stats ~= nil then

local block = stats:findFirstChild("Blocks")

block.Value = block.Value +10

wait(0.1)

script.Parent:Remove()

end

for _, child in pairs(model:GetChildren()) do

if child:IsA("BasePart") then

child.Touched:Connect(onModelTouched())

end

end

1 comment

0

My last answer was missing an end, sorry about that

1 answer

if you are using a local script, this might help:

local model = script.Parent

local hit = game.Players.LocalPlayer.Humanoid.Character.Touched --only on local script

local part = script.Parent--or whatever you want

local j = game.Workspace.Test.Part1

local k = game.Workspace.Test.Part

local user = game.Players:GetPlayerFromCharacter(hit.Parent)

local stats = user:findFirstChild("leaderstats")

local function onModelTouched(part)end

if part:IsDescendantOf(model) then return end

if stats ~= nil then

local block = stats:findFirstChild("Blocks")

block.Value = block.Value +10

wait(0.1)

script.Parent:Remove()

end

for _, child in pairs(model:GetChildren()) do

if child:IsA("BasePart") then

child.Touched:Connect(onModelTouched())

end

end

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