#what does "Otherpart" do?

1 messages · Page 1 of 1 (latest)

dense trail
#

Im new to lua and coding in general, and the parameter "otherpart" is confusing me. What does it do exactly? I found it off of a yt tutorial.

wintry wharf
#
print(otherPart)
#

so if we print otherPart

#

otherPart is ANYTHING that touches the part

#

meaning parts like SpawnLocation

#

and your body parts on your character

#

if we peek inside of a player thats loaded into the game

#

you can see all their body parts and something called "Humanoid"

#
local humanoid = otherPart.Parent:FindFirstChild("Humanoid")
#

thats where this comes in

#

so visualise it like this

LeftLowerLeg.Parent which is our model with your player name

#

thats why it prints my name

#

print(otherPart.Parent)

icy axleBOT
#

studio** You are now Level 16! **studio

wintry wharf
#

your character FINDTHEFIRSTTHINGCALLED ("Humanoid")

dense trail
#

oh wait so otherpart gets the first child of "Humanoid"?

#

i mean that little code segment

wintry wharf
#

otherpart is say your leg that touched the part
otherpart.Parent is your character

as your character is the parent of the leg

#

Gabeisvibing is my username ofc

everything inside is a child to it as its inside it

#

so all that code means is look inside Gabeisvibing for something called "Humanoid"

dense trail
#

oh ok

#

wait

#

another quick question

#

im making a quick little obby game to test my skills ya know

#

and i have this yellow ball thats a coin

#

when i touch the coin it doesn't make my leaderstat go up

wintry wharf
#

you named it coins not coin

#

i have made that mistake plenty of times too loll

#

https://www.youtube.com/watch?v=evBhoqeYegQ

if you want to make a player data saving system without needing to know to much just yet
i always recommend this as it helped me a ton

Today we look at a new library for easily saving player data inside of Roblox! The Profile Store library is created by the same developer of the Profile Service library, which we've used for saving our player data for so long.
Subscribe for more Roblox development tutorials!

Profile Store Dev Forum post:
https://devforum.roblox.com/t/profilesto...

▶ Play video
#

leaderstats is cool but not safe as youd have to save it on the client

dense trail
#

changing it to coins doesn't fix it either

#

wait out of curiosity

#

when doing the leaderstats thing you have a setINT for integer

#

i dont actually need a decimal but what if you wanted a decimal?

wintry wharf
#

no IntValue cant do floats

#

NumberValue

#
local num = Instance.new("NumberValue")
num.Value = 3.5
dense trail
#

oh ok

#

ok wait

#

should i make a seperate script for adding 1 to the player stats every time the player touches a coin? and if so where would that script go?

wintry wharf
#

i think you need to do
coins.Value += 1

#

which just means
coins.Value = coins.Value + 1

#

set whatever it is + 1

#
coinPart.Touched:Connect(function(otherpart)
    local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
    if humanoid then
        local player = game.Players:GetPlayerFromCharacter(otherpart.Parent)
        if player then
            local coins = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Coins")
            if coins then
                coinPart.Transparency = 0.7
                coins.Value += 1
            end
        end
    end
end)
#

another issue your having is it wont know what "coins" is

#

in your playeradded function you define what coins is so it knows

#

artist fr

#

the red part is outside of any function so its a global scope

meaning if you tried to reference something in global inside a functon no problem

#

anything in the green is in a function which is a local scope meaning only that function can see it

#
local coins = player:FindFirstChild("leaderstats") and player.leaderstats:FindFirstChild("Coins")
if coins then
    coinPart.Transparency = 0.7
    coins.Value += 1
#

so we tell it in your Touched function what coins is

#

its the folder inside of a specific player

#

then you can update their coins

wintry wharf
wintry wharf
dense trail
#

ok ty for the help man your a lifesaver

#

also another quick (probably) question

#

is there an easy way to remove a part from the game once something has happened

dense trail
#

nvm figured it out

#

again, thanks for the help

wintry wharf