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

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

Asked by
IsPoyo -1
5 years ago

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
0
My last answer was missing an end, sorry about that cmgtotalyawesome 1418 — 5y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Ad

Answer this question