game.Players.PlayerAdded:Connect(function(players)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = players
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
Coins.Value = 0
end)
local player = game.Players
local name = player:GetPlayerFromCharacter(player)
print(name)
game.UserInputService.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.E then
game.Players.name.Coins.Value += 1
end
if input.KeyCode == Enum.KeyCode.E then
print("Pressed E")
end
end)
#How to find player name when they join,
81 messages · Page 1 of 1 (latest)
I can find it using otherPart.Parent when they stand on a block but I dont want that
basically, code is when they reset, +1 deaths
stop skidding
cant u just do players.Name on the playeradded thing
I believe we can
brb setting up autoclicker to give myself infinite coins
PlayerAdded returns the player who joned so when you connect it to a function you can access the returned player as the first parameter.
game.Players.PlayerAdded:Connect(function(player)
** You are now Level 12! **
LOL fr
I am just doing random practise codes
I mean this aint working tho
local Player = game.Players.PlayerAdded:Connect(function(Player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = Player
local Username = Instance.new("StringValue")
Username.Name = "Username"
Username.Parent = leaderstats
Username.Value = Player.Name
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
Coins.Value = 0
end)
local CoinBag = game.Workspace.Door
CoinBag.Touched:Connect(function(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
local hit = true
print(hit)
if humanoid and hit == true then
print("Hello???")
print(Player.Name)
Player.Name.leaderstats.Coins.Value = Player.Name.leaderstats.Coins.Value +1
hit = false
print(hit)
task.wait(1)
end
end)
what's with the local hit thing
debounce
if you're trying to do a debounce it won't work because every time it's touched it's resetting
oh
local deb = true if deb then is basically just adding useless words
also most egregious is doing player = player added connect
?
what you've concepted to do is change the player we're talking about every time someone joins the game
so whenever anyone touches a coin it would give money to the last guy to join the game
Oh
and also the (Player) in brackets is the one used inside that function so player = blah is like not what u wanna be doing here
just do local plr = game.players:getplayerfromcharacter(character) if plr then
cuz u can't access the player inside the touched function
what about this tho
they're two separate blocks of code that don't communicate
but then how will this even make the player get +1 coin if they step on the block?
how will what do that
that's how you get which player stepped on the part
use the get player from character functionality of the playersservice
Is there a way to make this available to the whole script?
game.Players.PlayerAdded:Connect(function(players)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = players
local Username = Instance.new("StringValue")
Username.Name = "Username"
Username.Parent = leaderstats
Username.Value = players.Name
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
Coins.Value = 0
--leaderstats
end)
thats why I was doing local player = this
you shouldn't in this situation
you're correct in that giving players their leader stats and giving them money when they touch a part are two separate concepts
all you need to do is run the code i gave you
game.Players.PlayerAdded:Connect(function(players)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = players
local Username = Instance.new("StringValue")
Username.Name = "Username"
Username.Parent = leaderstats
Username.Value = players.Name
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
Coins.Value = 0
--leaderstats
--locate player
local PlayerName = players.Name
print(PlayerName)
--got player
local CoinBag = game.Workspace.Door
CoinBag.Touched:Connect(function(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
--if a character touches it
local PlayerName = players
if humanoid then
local hit = true
if humanoid and PlayerName and hit == true then
while hit == true do
PlayerName.leaderstats.Coins.Value += 1
task.wait(1)
break
end
hit = false
end
end
end)
end)
AND IT WORKS
JUST A FEW ATTEMPS
holy i am happy
don't do that
now every time someone touches a coin it will give everyone in the game money
you also set player name twice in the same function and like rather uselessly
also while hit == true do blah break is insane work
I added the debounce this time
local debounce = false
game.Players.PlayerAdded:Connect(function(players)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = players
local Username = Instance.new("StringValue")
Username.Name = "Username"
Username.Parent = leaderstats
Username.Value = players.Name
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
Coins.Value = 0
--leaderstats
--locate player
local PlayerName = players.Name
print(PlayerName)
--got player
local CoinBag = game.Workspace.Door
CoinBag.Touched:Connect(function(otherPart)
local character = otherPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
--if a character touches it
local PlayerName = players
if humanoid and not debounce then
debounce = true
if humanoid and PlayerName and debounce == true then
while debounce == true do
PlayerName.leaderstats.Coins.Value += 1
break
end
end
end
wait(1)
debounce = false
end)
end)
why
I gues it dont matter
tbnh
tbh
since its in the if
how do I change that
No
try touching the coin with player1
Fair enough
game.Players.PlayerAdded:Connect(function(players)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = players
local Username = Instance.new("StringValue")
Username.Name = "Username"
Username.Parent = leaderstats
Username.Value = players.Name
local Coins = Instance.new("IntValue")
Coins.Name = "Coins"
Coins.Parent = leaderstats
Coins.Value = 0
end)
local debounce = false
local CoinBag = workspace.Door
CoinBag.Touched:Connect(function(otherPart)
if not otherPart.Parent then return end --guy died
local character = otherPart.Parent
local humanoid = character:FindFirstChildOfClass("Humanoid")
--if a character touches it
local PlayerName == game.Players:GetPlayerFromCharacter(character) --find player
if humanoid and PlayerName and debounce == false then
debounce = true
PlayerName.leaderstats.Coins.Value += 1
task.wait(1)
debounce = false
end
end
end)
can you see the difference here
If not otherPart.Parent
Right?
there's more than that that one's kinda inconsequential
just catching if the part like gets deleted at the same time so we don't error looking for its parent
i'm talking more philosophically
the biggest is using that get player from character thing i was talking about
that's how we access the player who touched
but i also cut out all the wack crap going on with the debounce
saying debounce = true if debounce == true is frankly a little silly because it's always going to be true
and the concept of checking if debounce is false, setting it to true and then checking whether it's true is insane because we already know the value of debounce and we then set it to something else so we know it twice and then try to figure out what it is a third time
and adding a while loop for no reason is also nuts
i think u might've over engineered it a bit cuz stuff wasn't working
but try to remember the fundamentals and maybe take a walk around outside if stuff isn't working and come back to it
Yeah I didn’t really know what to do tho much since I started this month
** You are now Level 8! **
that's fine that's why we're learning
try to break problems down into individual parts and find stuff on the internet about it
like how to get player who touched part etc
It’s -8 degrees 🙂 so I’ll take a walk to my fridge instead
nice
Alright Ty
Ty for the help