#Help

113 messages · Page 1 of 1 (latest)

magic iris
#

Here are my scripts
Leaderstats script

local Players = game:GetService("Players")

local function leaderboardSetup(player)
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player
    
    local rng = Instance.new("IntValue")
    rng.Name = "Rng"
    rng.Value = 0
    rng.Parent = leaderstats
end

Players.PlayerAdded:Connect(leaderboardSetup)

Give points script

local part = game.Workspace.MyButton
clickDetector = game.Workspace.MyButton.ClickDetector

clickDetector.MouseClick:Connect(function(onClick)
    amount = math.random(1,10000)
    game.Players.LocalPlayer.leaderstats.Rng.Value = game.Players.LocalPlayer.leaderstats.Rng.Value + amount
    print(amount)
end)

The error

Workspace.MyButton.ClickDetector.Script:6: attempt to index nil with 'leaderstats'

So what I'm doing is going into the the player with game.player then the localplayer then the folder leaderstats and then the intvalue rng. But it keeps getting this error. Idk what to do.

fluid fjord
#

You can't access the LocalPlayer property from the server.

magic iris
#

Wdym

#

Oh

#

So what do I do

#

I changed it

fluid fjord
#

The MouseClick signal passes the player as the first argument.

magic iris
#

I used to be called player

#

But I changed to onClick

#

Im new to scripting

fluid fjord
#

Take a look at the code sample on the docs for an idea on how to use the MouseClick event.

magic iris
#

I just did that but it still doesn't work

fluid fjord
magic iris
#

Same error

#

local part = game.Workspace.MyButton
clickDetector = game.Workspace.MyButton.ClickDetector

clickDetector.MouseClick:Connect(function(player)
amount = math.random(1,10000)
game.Players.LocalPlayer.leaderstats.Rng.Value = game.Players.LocalPlayer.leaderstats.Rng.Value + amount
print(amount)
end)

magic iris
#

But then I changed to a yt video

distant flume
#

player.leaderstats.Rng.Value = player.leaderstats.Rng.Value + amount

royal bridge
#

help me next pls

magic iris
#

Oh

#

Let me try that

#

IT WORKS TY

#

So instead of game.player.localplayer.leaderstats.rng.value and copy paste then = and then = amount

flint thunderBOT
#

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

magic iris
#

It's just player.leaderstats.rng.value += amount

#

Ty

magic iris
#

Hey

#

I made a new script

#
local part = script.Parent
amount = (10)

local function player()
        player.LocalPlayer.leaderstats.Rng.Value += amount
        print("You just got amount rng :D")
end
    
part.Touched:Connect(player)
#

Getting the same error

#

I removed the LocalPlayer

#

And didn't work so I added it back and it's the same thing

#

Also the error is this

#

Workspace.GtRng.Script:5: attempt to index function with 'LocalPlayer'

#

And if I remove LocalPlayer it does

#

Workspace.GtRng.Script:5: attempt to index function with 'leaderstats'

#

Oh do I need this? local Players = game:GetService("Players")

#

Is that not the same thing?

#

Oh 10 doesn't need parentheses

#

ohhhhh function player(player)

#

What does adding (player) do?

#

I want to understand so I don't keep making mistakes

#

What does an argument do?

#

I thought that was a paramiter

#

Like for kill(otherPart)

#

Oh ok

#

Wait I got an error from the script you gave

#

leaderstats is not a valid member of Part "Workspace.Baseplate"

#

Idk

#
local part = script.Parent
amount = 10

local function player(player)
    player.leaderstats.Rng.Value += amount
    print("You just got amount rng :D")
end

part.Touched:Connect(player)
#

This is what I used

#

?

#

part

#
local part = script.Parent
#

????

#

Confusion

#

It's the part

#

That I'm using in the game

#

It's a green block with 0.5 transparency

#

I used to have a thing in the script where it was

#
local part = script.Parent
amount = 10

local function player(otherPart)
    partParent = otherPart.Parent
    humanoid = partParent:FindFirstChild("Humanoid")
    if humanoid then
    player.leaderstats.Rng.Value += amount
    print("You just got amount rng :D")
end

part.Touched:Connect(player)
#

Idk how to do that

#

Since I started scripting a few days ago

distant flume
#

local part = script.Parent
amount = 10

local function player(partThatTouched)
local getPlayer = game:GetService("Players"):GetPlayerFromCharacter(partThatTouched.Parent)

if getPlayer then
    player.leaderstats.Rng.Value += amount
    print("You just got amount rng :D")
end

end

part.Touched:Connect(player)

magic iris
#

So I do need the local getPlayer = game:GetService("Players"):GetPlayerFromCharacter(partThatTouched.Parent)

#

Let me see

#

local Players = game:GetService("Players"):GetPlayerFromCharacter(partThatTouched.Parent)

#

Wdym

#

And?

distant flume
magic iris
#

Still doesn't work

#

Workspace.GtRng.Script:8: attempt to index function with 'leaderstats'

#

This is the error

#

All I changed was getPlayer to players

flint thunderBOT
#

studio** You are now Level 4! **studio

magic iris
#

Does partThatTouched need to be player?

distant flume
#

player.leaderstats needs to be players.leaderstats

magic iris
#

Oh ok

#

It works

#

Lesss go

magic iris
#

Every step on the block is a point

#

I'ma add a cooldown

#

Hey quick question

#

How do I add a wait

#
local part = script.Parent
amount = 100000

    local function player(partThatTouched)
    local players = game:GetService("Players"):GetPlayerFromCharacter(partThatTouched.Parent)
    if players then
        players.leaderstats.Rng.Value += amount
        print("You just got 100,000 rng :D")
        end
    end

    part.Touched:Connect(player)
#

I tried adding

#
local part = script.Parent
amount = 100000

    local function player(partThatTouched)
    task.wait(1)
    local players = game:GetService("Players"):GetPlayerFromCharacter(partThatTouched.Parent)
    if players then
        players.leaderstats.Rng.Value += amount
        print("You just got 100,000 rng :D")
        end
    end

    part.Touched:Connect(player)
#

But that only works when I'm on the block and spam jump

#

If I just walk on and off it keeps going

#

Where do I put it

distant flume
#

That's not going to work

#

All you're doing is delaying the code by 1 second

#

It's still going to fire multiple times

magic iris
#

Oh

#

Like

#

I cant just walk off and on multiple times

#

And spam get it

#

Instead

#

If I walk on then theres a 1 second cooldown before I can get points from walking on it again

#

How do I do a debounce

#

Alr

#

I will search up

distant flume
#

local part = script.Parent
amount = 100000

local onCooldown = false

local function player(partThatTouched)
if onCooldown == false then
local players = game:GetService("Players"):GetPlayerFromCharacter(partThatTouched.Parent)

    if players then
        onCooldown = true
        players.leaderstats.Rng.Value += amount
        print("You just got 100,000 rng :D")
        
        task.wait(NUMBER)
        
        onCooldown = false
    end
end

end

part.Touched:Connect(player)

#

this will work

magic iris
#

But ty anyways

#

I got this

#
local part = script.Parent
amount = 100000
local RESET_TIME = 1

    local function player(partThatTouched)
    local players = game:GetService("Players"):GetPlayerFromCharacter(partThatTouched.Parent)
    if players then
        
        if not part:GetAttribute("Touched") then
            part:SetAttribute("Touched", true)
            players.leaderstats.Rng.Value += amount
            print("You just got 100,000 rng :D")
            task.wait(RESET_TIME)
            part:SetAttribute("Touched", false)
        end
        end
    end

    part.Touched:Connect(player)
distant flume
#

there's multiple ways to do it

#

all that matters is that it works