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
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