#Just started out Luau.

1 messages · Page 1 of 1 (latest)

pearl flare
#

I converted to roblox luau after using python for a while. I followed BrawlDev's beginner series all teh way to the end. But now whenever I touch the coin, I gain more than 1 coin in the coin.value, I have not added a math.random value yet. Here are the scripts

server script under coin in workspace

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats

local coin = game.Workspace:FindFirstChild("coin")



coin.Touched:Connect(function(otherpart)
    local player = game.Players:GetPlayerFromCharacter(otherpart.Parent)
    local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
    if humanoid and player then
        player.leaderstats.Coins.Value += 1
        coin.CanTouch = false
        coin.Transparency = 0.9
    end
end)    

end)

Server script in coin2 under workspace

local coin = game.Workspace:FindFirstChild("coin2")

coin.Touched:Connect(function(otherpart)
local player = game.Players:GetPlayerFromCharacter(otherpart.Parent)
local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
if humanoid and player then
player.leaderstats.Coins.Value += 1
coin.CanTouch = false
coin.Transparency = 0.9
end
end)

please help 😭

#

Also same thing with the timer, it says x6 or x2 or something, im assuming it cus multiple parts of my body touches it. How do I fix this?

#

Timer script under Button

script.Parent.Touched:Connect(function(otherpart)
local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
local touched = false
local wall = game.Workspace:FindFirstChild("Wall")
local button = game.Workspace:FindFirstChild("Button")

wall.Transparency = 0.5
wall.CanCollide = false

if humanoid and touched == false then
    
    for timer = 5, 1, -1 do
        touched = true
        button.CanTouch = false
        print(timer)
        task.wait(1)

        if timer == 1 then
            touched = false
            button.CanTouch = true
            wall.Transparency = 0
            wall.CanCollide = true
        end
    end
end

end)

safe tundra
pearl flare
#

I have added .cantouch = false rigtht after the value has been added so that it cannot be touched again but it seems that it doesnt work

safe tundra
pearl flare
# safe tundra set a variable that could be anything like "local debounce = false" once it get...

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats

local coin = game.Workspace:FindFirstChild("coin")



coin.Touched:Connect(function(otherpart)
    local player = game.Players:GetPlayerFromCharacter(otherpart.Parent)
    local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
    local debounce = false
    if humanoid and player and debounce == false then
        player.leaderstats.Coins.Value += 1
        coin.CanTouch = false
        coin.Transparency = 0.9
        task.wait(1)
        local debounce = true
    end
end)    

end)

?

#

like this?

safe tundra
#
local debounce = false

game.Players.PlayerAdded:Connect(function(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Value = 0
    coins.Parent = leaderstats

    local coin = game.Workspace:FindFirstChild("coin")



    coin.Touched:Connect(function(otherpart)
        if debounce then return end
        debounce = true
        local player = game.Players:GetPlayerFromCharacter(otherpart.Parent)
        local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
        if humanoid and player then
            player.leaderstats.Coins.Value += 1
            coin.CanTouch = false
            coin.Transparency = 0.9
            task.wait(1)
        end
        debounce = false
    end)
end)
#

hold im editing

#

that should be good

pearl flare
#

Alr I’ll try

viral wadiBOT
#

studio** You are now Level 2! **studio

safe tundra
#

messed up a tiny bit but i fixed it dw

pearl flare
#

dammm

#

it works

#

ty

safe tundra
#

yes yes

pearl flare
# safe tundra yes yes

Can u do a brief explanation? I was analysing the code and I still don’t really understand what “return” really does. Thanks!

safe tundra
#

so if debounce is true it returns and stops the code

pearl flare
#

Ohh I see, thanks! 🙏

green crest
#

return checks for something

#

return end basically makes that if such function executes its gonna get ended

#

end is the one that ends the operation completly

safe tundra
green crest
#

lmao

pearl flare
#

I think it’s like

green crest
#

yes indeed

pearl flare
#

If debounce

#

Return

#

End)

#

To close

green crest
#

no

#

then

pearl flare
#

Yeah

green crest
#

if debounce then

pearl flare
#

Im on mobile i cant shift enter crying

green crest
#

just like : in python anywyas

pearl flare
#

Yes

green crest
#

but yes trust me

#

return

#

is gonna make you feel like a british kid waking up for a fish filet

pearl flare
#

Lmao what crying

green crest
#

returns are the most wonderful thing in luau

#

but i will let you judge lmao

pearl flare
#

Ok lol

#

When I get more advanced I’ll prob use it in studio

#

I just don’t understand lua’s goofy syntax lmao

safe tundra
#

hes just a hater

green crest
#

shat up

pearl flare
#

We beefing over a function now 💀 😭

#

Lmao

#

RSC close this chat

#

I learnt the ways of the returns

#

I shall now destroy those who use script.parent.parent.parent.parent.parent to locate an instance Thumbs

#

Thank me later

sinful kite
#

Return immediately ends the current function and sends values back to the caller if provided.
A return statement is just telling the C interpreter to move the stack struct.

#

The closest ”check” you’ll get is a nullptr check so you don’t crash the C interpreter.

green crest
#

ends and returns the end

sinful kite
#

if true then return end doesn’t return ”end”, they’re both EOF signals to the compiler to stop executing the code. / go out of scope

green crest
#

oh mb then

#

got it wrong

sinful kite
#

all good capybarathink

safe tundra
pearl flare
#

He didn’t spoon feed, im the one who ate the spoon

pearl flare
#

Wait I was gonna ask something but I forgot

viral wadiBOT
#

studio** You are now Level 3! **studio

pearl flare
#

It was important crying

pearl flare
#

local debounce = false

game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player

local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats

local coin = game.Workspace:FindFirstChild("coin")



coin.Touched:Connect(function(otherpart)
    if debounce then return end
    debounce = true
    local player = game.Players:GetPlayerFromCharacter(otherpart.Parent)
    local humanoid = otherpart.Parent:FindFirstChild("Humanoid")
    if humanoid and player then
        player.leaderstats.Coins.Value += 1
        coin.CanTouch = false
        coin.Transparency = 0.9
        task.wait(1)
    end
    debounce = false
end)

end)

aight so i wanna know why debounce is false afterwards? shouldnt i eb kept as true so Iit cant run more than once?

sinful kite
#

Otherwise it functions as a cooldown for how long it is until you’re able to perform that action again

pearl flare
#

Ty, though when I did that my code didnt work crying