/ / Dlaczego ten skrypt nie działa? - lua, roblox

Dlaczego ten skrypt nie działa? - Lua, Roblox

Poniższy skrypt dzieli między print („2”) a print („3”), ponieważ nie może znaleźć zmiennej „tag”. Jak mam to naprawić?

local Humanoid = script.Parent.Zombie -- Or Zombie Or Whatever
function PwntX_X()
print("1")
local tag = Humanoid:findFirstChild("creator")
print("2")
if tag ~= nil then
print("3")
if tag.Value ~= nil then
print("4")

local Leaderstats = tag.Value:findFirstChild("leaderstats")
print("5")
if Leaderstats ~= nil then
print("6")
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 5
print("7")
wait(0.1)`enter code here`
script:remove()
end
end
end
end
Humanoid.Died:connect(PwntX_X)

Mam już skrypt do tablicy wyników, który działa w 100%. Ten skrypt jest używany w grze o nazwie „ROBLOX”. Dzięki!

Odpowiedzi:

0 dla odpowiedzi № 1

W porządku, po pierwsze skryptinghelpers.org został stworzony jako usługa podobna do stackoverflow specjalnie dla Robloxa, sugeruję następnym razem, kiedy poprosisz tam, teraz o rzeczy;

-- If you have further problems, My Roblox username is "ZeroBits" (REMOVE THIS LINE)

DEBUG = true -- Debug Print, so you can disable it when you"re done.
local function print_D(t)
if DEBUG == true then warn(t) end end
print_D("DEBUG MODE, Switch Debug Value to False when finished")

local Humanoid = script.Parent:FindFirstChild("Zombie") -- We"ll use FindFirstChild() here
--if not Humanoid then -- Uncomment this statement if you want it to affect objects named Humanoid as well
--    Humanoid = script.Parent:FindFirstChild("Humanoid")
--end
function HumanoidKilled() -- Renamed the function to be a little less cringeworthy
print_D("1") -- switched these print statements with the Print_D() function
local tag = Humanoid:FindFirstChild("creator") -- Capitalized the first letter in FindFirstChild()
print_D("2")
if not tag then
warn("No Tag Found check Humanoid and weapon script")  --if this prints, there"s either no tag, or a serious problem, and you should check the humanoid object for a tag, or make sure the weapons you use actually generate tags.
else -- changed "if tag ~= nil then" to "if not tag then "do stuff" else" to simplify the code, and add an else statement early on.
print_D("3")
if tag.Value then -- removed "~= nil" because it"s just useless clutter
print_D("4")
local Leaderstats = tag.Value:findFirstChild("leaderstats")
print_D("5")
if Leaderstats ~= nil then
print_D("6")
Leaderstats.Cash.Value = Leaderstats.Cash.Value + 5
print_D("7")
wait(0.1)
script:Destroy() -- switched remove() to Destroy(), remove() is deprecated
end
end
end
end
Humanoid.Died:connect(HumanoidKilled)

To rozwiązuje wszystkie problemy w skrypcie iczyni to bardziej wydajnym. jeśli nadal występują problemy, jest to albo w skrypcie tworzenia tagów, tagi nie są przechowywane w humanoidzie, albo tagi nie są nazywane „twórcami”

zmieniłem także instrukcje drukowania na afunkcja print_D, która używa warn () zamiast print (), nie ma prawie żadnej różnicy, z wyjątkiem tego, że tekst debugowania pojawi się w konsoli na żółto, a nie na biało.

skrypt jest używany w grze o nazwie „ROBLOX”. Dzięki!

To jest gra na Robloxie, a nie gra o nazwie Roblox, to, co powiedziałeś, jest podobne do powiedzenia; Stworzyłem ten mod do Source Engine, kiedy faktycznie stworzyłeś mod do Half-Life 2