Also I read the documentation on LuaSourceContainer, which reads that it is the source of all scripts.
wait
it was comming from my 4k coin collectors
i deleted them and it works fine
but i might try to add a new one without printing 4k times
but thank you for helping me
i think these parts are useless and might cause lag
I can still try and fix the error. Just paste the script segment that errors.
Alright. If you want to just remake it, I don’t mind.
wait wait i think the error was comming from this script
amnt = 700 --how much you get for it
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if (h~=nil) then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if (thisplr~=nil) then
local stats = thisplr:findFirstChild("leaderstats")
if (stats~=nil) then
local score = stats:findFirstChild("Blocks")
if (score~=nil) then
score.Value = score.Value + amnt
end
end
end
script.Parent:remove()
end
end
script.Parent.Touched:connect(onTouched)
amnt = 700 --how much you get for it
function onTouched(part)
local h = part.Parent:findFirstChild("Humanoid")
if h then
local thisplr = game.Players:findFirstChild(h.Parent.Name)
if thisplr then
local stats = thisplr:findFirstChild("leaderstats")
if stats then
local score = stats:findFirstChild("Blocks")
if score then
score.Value += amnt
end
end
end
script.Parent:remove()
end
end
script.Parent.Touched:connect(onTouched)
I can’t find any errors, but I polished your code. Is the first parameter, part
, being returned in a print()
?
wait let me try it…
because idk why
uhh the problem isnt occuring anymore i will tell you if it happens
Mabye it was your coding style. It’s really messy, and definitely needed some polishing.
wait a minute…
it stopped happening and then it starts and stops what is happening over here
i need to remove the thing so it dosent break the players computer fan
Switch your code out with this:
--//Services
local Players = game:GetService("Players")
--//Variables
local Part = script.Parent
--//Controls
local amount = 700
--//Functions
Part.Touched:Connect(function(hit)
local player = Players:GetPlayerFromCharacter(hit.Parent)
if player then
Part:Destroy()
player.leaderstats.Blocks.Value += amount
end
end)
I see an error in your code:
Part
, the parent of script
, gets deleted before anything can be done. This renders the leaderstats
value unreachable.
Correct me if I’m wrong.
No it doesn’t. If you know anything about how scripts/threads run, the entire thread runs even if the parent was destroyed first.
Ah. That makes sense, after testing. I still find it strange to delete the parent before any changes.
I delete the parent first so that in the split milliseconds that it takes for the value to add, the player can’t fire the touched event again. It’s just a prevention for that edgecase.
it takes a while for the error comes but i will make this as a solution
even tho my fans are spinning very fast on this it still works (i think)
idk why my computer is making a rollar coaster breaking noise