#im lowk a dumbass and i need help
1 messages · Page 1 of 1 (latest)
l```lua
local Part = script.Parent
Part.Touched:Connect(function(otherPart)
local Humanoid = otherPart.Parent:WaitForChild("Humanoid")
if Humanoid then
Humanoid.Health = 50
local Egg = math.random(1, 800)
while Egg <= 800 do
if Egg <= 10 then
print("???")
elseif Egg <= 75 then
print("Godly")
elseif Egg <= 185 then
print("Mythic")
elseif Egg <= 285 then
print("Legendary")
elseif Egg <= 385 then
print("Epic")
elseif Egg <= 485 then
print("Rare")
elseif Egg <= 585 then
print("Uncommon")
elseif Egg <= 700 then
print("Common!")
elseif Egg == 800 then
print("You're a Bum.")
task.wait(2)
if Egg == 5 then
break
end
end
end
end
end)
@fading shore
** You are now Level 1! **
what do u need help with
well, all it does is bring a useless loop and get egg's value once
Try not to use waitforchild in this situation
buy
but
i thought u have to use it
since
i dont want it launching as soon as i run the game
that’s what the “if Humanoid” is for
i wnat it to like keep telling u what u got and then break after a bit
so i use findfirst child?
Yes
local Humanoid = otherPart.Parent and otherPart.Parent:FindFirstChild("Humanoid")
if not Humanoid then return end
Also what’s the script doing
where do i put that
im ed
local Humanoid = otherPart:FindFirstChild(“Humanoid”) or nil
if not Humanoid then return end
mb
i thought humanoid will always be true
otherpart is the part that touched, the model is the parent
I hate scripting on a phone
i don’t understand
also you don’t need a while loop
so look
That entire function will start every time a player touches the part
Instead of a while loop just do the if statements
You don’t need a loop if it’s going to give you a item every time it’s touched otherwise it’ll infinitely print until you hit the 5
Part.Touched:Connect(function(otherPart)
local Humanoid = otherPart.Parent and otherPart.Parent:FindFirstChild("Humanoid")
if not Humanoid then return end
if Humanoid then
local Egg = math.random(1, 800)
if Egg <= 10 then
print("???")
elseif Egg <= 75 then
print("Godly")
elseif Egg <= 185 then
print("Mythic")
elseif Egg <= 285 then
print("Legendary")
elseif Egg <= 385 then
print("Epic")
elseif Egg <= 485 then
print("Rare")
elseif Egg <= 585 then
print("Uncommon")
elseif Egg <= 700 then
print("Common!")
elseif Egg == 800 then
print("You're a Bum.")
end
end
end)```
this one prints everytime a part of your body touches
** You are now Level 1! **
i can edit it so you need to touch once for infinite replies
its just changing how u get humanoid
removed loop
so what was the error?
and getting value of 5
just the loop?
yeah
if humanoid is not found then dont do anything
i thought thats what waitforchild is
wait for child pauses the script until humanoid is found
yeah
alr thanks
it’s also unnecessary resource usage
wym
the humanoid is there to detect if its a character
if not game.Players:GetPlayerFromCharacter(otherPart.Parent) then return end
also works
yooo thats tuff
what does return do
** You are now Level 2! **
@deft dirge
Return replies a value in function and keeping it empty stops the code
just like how break stops a loop
Basically ends the code there
Or ```local function hi()
return "hi"
end
Hello = hi()
This will make Hello be "hi"
Return can makes you "escape" the function, so you tell the code of the function to stop where u put return, return could also be used to return us values, what do i mean by thats, is that if we make a function
local function addition(number1,number2)
local number3 = number1 + number2
return number3
end
local result = addition(5,2) -- result = 7 since number 3 with this function is 7, and we said the function that it will be equal to number3
--another ewample
local otherResult = addition(3,2) -- 5 since here number3 is equal to 5
And if u still dont understand dont worry, if we keep saying the same thing, a time will come u will understand immediatly
