#1 playrer game

80 messages · Page 1 of 1 (latest)

mystic spindleBOT
#

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

wraith jungle
#
local p = game.Workspace.Seller.Sell
p.Touched:Connect(function(hit)
    if game.Players[hit.Parent.Name] then
      game.Players[hit.Parent.Name].leaderstats.Money.Value += 1
      hit:Destroy()
    end
end)
timid canopy
# wraith jungle ```lua local p = game.Workspace.Seller.Sell p.Touched:Connect(function(hit) ...

I would rather do this because what if there are multiple players with the same name? + What if the DisplayName is different and not the same as the Username?

local p = game.Workspace.Seller.Sell
p.Touched:Connect(function(hit)
    if not hit.Parent:FindFirstChild("Humanoid") or not game.Players:GetPlayerFromCharacter(hit.Parent:FindFirstChild("Humanoid")) then return end
    game.Players:GetPlayerFromCharacter(hit.Parent:FindFirstChild("Humanoid")).leaderstats.Money.Value += 1
    hit:Destroy()
end)
timid canopy
#

?

#

So there are no errors?

#

my mistake, sorry.

timid canopy
#

?

#

any errors?

#

The script is supposed to add 1 to the "Money" Counter Value and after that, it shall destroy the object that the player has touched.

#

Any errors?

#

Can you show me an Video of you interacting with the block?

timid canopy
#

you pasted it again and tested it?

#

and it does nothing?

#

uhh

#

Okay 1sec. I'll test it out in my game..

#

no, nw. I think I figured out why. I did a dumb mistake with my script...

#
local p = game.Workspace.Seller.Sell
p.Touched:Connect(function(hit)
    if not hit.Parent:FindFirstChild("Humanoid") or not game.Players:GetPlayerFromCharacter(hit.Parent) then return end
    game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Money.Value += 1
    hit:Destroy()
end)
#

That one should work now.

#

errors?

#

oh.. I forgot to change it in the second spot

#

but it should've printed an error.

#

u sure?

#

yeah alright

mystic spindleBOT
#

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

timid canopy
#

same error?

#

show me please.

#

Show me the full error please.

#

With the red text thing.

timid canopy
#

I mean I can of course modify it a bit.. but that error shouldn't be possible with the way we use it...

#

final try:

local p = game.Workspace.Seller.Sell
p.Touched:Connect(function(hit)
    if not hit.Parent or not hit.Parent:FindFirstChild("Humanoid") or not game.Players:GetPlayerFromCharacter(hit.Parent) then return end
    game.Players:GetPlayerFromCharacter(hit.Parent).leaderstats.Money.Value += 1
    hit:Destroy()
end)
#

good

#

alright

#

so it works

#

1sec

mystic spindleBOT
#

studio** You are now Level 5! **studio

timid canopy
#

now it should add the Money.

#

(I just removed the mony giving thing because I just copy and pasted my test script)

#

oh

#

because

#

I used.

timid canopy
#

(It was because I copied some parts of the other script above and because discord formatted it so I got confused and accidentally pasted it wrong.. oopsys)

#

nice

#

wdym?

#

OH

#

you want it so that if a part is touching it, it adds the value to the one player in-game?

#

Well I can modify the script so it works for max. 1 Player ofc.. If you want to make it able to be played in multi-player then it will break.

#

how are the parts called which are touching it?

#

"A"?

#

alr

wraith jungle
timid canopy
#

yeah, nw

wraith jungle
timid canopy
#

Oh, really?

wraith jungle
#

idk

timid canopy
#

I thought it would be the display name one..

#

yeah I'm not sure

wraith jungle
#

im not on my pc rn

#

ill check later

timid canopy
#

nw, we are nearly done with the script

#

I think the problem will be resolved really soon

#

Maybe I scripted it toooooo safe but in case the script gets executed before the player is actually really joined...

#
local _player = game.Players:GetPlayers()[1] or false
local _moneyToAdd = 0
game.Players.PlayerAdded:Connect(function(plr)
    if not _player then _player = plr end
    if _moneyToAdd ~= 0 then
        plr:WaitForChild("leaderstats"):WaitForChild("Money").Value += _moneyToAdd
        _moneyToAdd = nil
    end
end)

local p = game.Workspace.Seller.Sell
p.Touched:Connect(function(hit)
    if hit.Name ~= "A" then return end
    if not _player then _moneyToAdd+=1 end
    _player.leaderstats.Money.Value += 1
    hit:Destroy()
end)
#

(Here are 2 Alternative Versions in case you don't want to use that)

local _player = game.Players:GetPlayers()[1] or false
game.Players.PlayerAdded:Connect(function(plr)
    if not _player then _player = plr end
end)

local p = game.Workspace.Seller.Sell
p.Touched:Connect(function(hit)
    if hit.Name ~= "A" then return end
    if not _player then return end
    _player.leaderstats.Money.Value += 1
    hit:Destroy()
end)
local _player = game.Players:GetPlayers()[1]
local p = game.Workspace.Seller.Sell
p.Touched:Connect(function(hit)
    if hit.Name ~= "A" then return end
    _player.leaderstats.Money.Value += 1
    hit:Destroy()
end)
timid canopy
#

Up to you what you wanna use.

#

np

#

Alright! If everything is working fine, then please mark this Thread as resolved! @quartz knoll

#

Should be somewhere there.

#

"Add Tag" -> Solved

#

or smth like that

#

Alright!