#1 playrer game
80 messages · Page 1 of 1 (latest)
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)
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)
Try this @quartz knoll
- Are there any errors you get when executing that script?
?
So there are no errors?
my mistake, sorry.
I update it. ^
Oh light! I know why yours probl. didn't work. I think it's because you did that "." after a "]" in line 4.
?
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?
Okay.. I modified it a bit.. Try it with that one now.
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
paste that one.
** You are now Level 3! **
same error?
show me please.
Show me the full error please.
With the red text thing.
u sure you used that one?
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
now modify it "back" to this
** You are now Level 5! **
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.
yeha just paste that again
(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
idk i just wrote it on here
yeah, nw
also i think the character model name is the same as the player's name not the display one
Oh, really?
idk
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)
That one is the "failure-safest" one but maybe it's not necessary.
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!