My script doesn’t seem to be working. It isn’t changing the values as intended. Any ideas why?
located in the button:
local Doge = game.ServerStorage.Doge
local cost = 0
local Button = script.Parent
local Values = script.Parent.Parent.Parent.Parent.Values
local plr = script.Parent.Parent.Parent.Parent.Values.PlayerName.Value
local DepositedCoins = Values.DepositedCoins
Button.Touched:Connect(function(hit)
if hit.Parent.Name == plr then
DepositedCoins.Value += plr.Dogecoins.Value
plr.Dogecoins.Value = 0
end
end)
1 Like
That’s because you’re checking if the hit parent’s name is the player. You should instead check if the hit part is a descendant of the player’s character.
Button.Touched:Connect(function(HitPart)
if HitPart:IsDescendantOf(Player.Character) then
DepositedCoins.Value += plr.Dogecoins.Value
plr.Dogecoins.Value = 0
end
end)
I tried your response just now and got this error:
Workspace.Area1.DepositArea.Buttondeposit.Top.Script:10: attempt to index nil with ‘Value’
Any ideas why that has happened???
Read the error, it says line 10, and trying to get Value from something that doesnt exist. Probably this:
plr.Dogecoins.Value
That plr.Dogecoins
doesnt exist.
Probably cause this, its pretty messy, what does that even mean?:
local plr = script.Parent.Parent.Parent.Parent.Values.PlayerName.Value
Parent x4 then a folder called values, then PlayerName??.. a value called literally “PlayerName”? not a real name? just “PlayerName”?
Geez sorry I am messy Made it neater and nothing changed.
Its ok, you just need to redo the logic after that script, show what you have right now
local Doge = game.ServerStorage.Doge
local cost = 0
local Button = script.Parent
local Values = game.Workspace.Area1.Values
local plr = Values.PlayerName.Value
local DepositedCoins = Values.DepositedCoins
Button.Touched:Connect(function(HitPart)
if HitPart:IsDescendantOf(plr.Character) then
DepositedCoins.Value += plr.Dogecoins.Value
plr.Dogecoins.Value = 0
end
end)
local Values = game.Workspace.Area1.Values
local plr = Values.PlayerName.Value
That plr variable doesnt contain a value in the player.
I mean, this is a server script, when the script runs, it doesnt know the PlayerName, you are literally looking for something called “PlayerName” not the value that belongs to the real Player’s Name
You should find the player when the button is touched, not outside the touched event.
Player touch the button, you identify the player, then you go to check values in your folder that are related to that player
So I need to move that to the inside of the touched event?
1 Like
Look, you call it button, but it seems more like a coin that on touch, should increase a Player’s value, right?
So, on touch, you should get the player that touched it, find the player’s value that should be increased. Then whats the value’s name you want to increase? its DepositedCoins? or Dogecoins?
Hi, your issue seems pretty easy to solve. What is “PlayerName”? A StringValue?
Figured it out partially! I found out I need to put game.Players before it but it thinks I’m trying to find something called plr in players. Any ideas on how that could be done?
It is a StringValue yea! Is that an issue?
Well, it seems as if you’re trying to access the player instance using a string (PlayerName.Value).
Button.Touched:Connect(function(hit)
if hit.Parent.Name == plr then
local actualPlayer = game.Players[plr]
DepositedCoins.Value += actualPlayer.Dogecoins.Value
actualPlayer.Dogecoins.Value = 0
end
end)
In the script above, i’m accessing the player instance using the ‘plr’ variable you’ve created, which I assume holds the name of the player. Then I just get the instance from the Players service and I can do whatever actions I need to perform, for example changing the ‘Dogecoins’ value.
Um so I tried this and and it still hasn’t worked. Except this time there was no errors. Neither values have changed.
Its needed to have more context of what this does mean, where is it?
script.Parent.Parent.Parent.Parent.Values.PlayerName.Value
I find it hard that value is actually inside the coin, or if that holds a string pointing to the player
ofc it has no errors, cause script.Parent.Parent.Parent.Parent.Values.PlayerName.Value
is not equal to hit.Parent.Name
so it never runs
I have a bunch of folders thats why it looks like that. The scripts in the button, and playername is in the values folder.
I recommend adding a few prints (debugging) to make sure everything is setup correctly. There’s multiple possibilites as to why the script is not working.
For instance, it’s possible the if
is failing, which would then mean either hit.Parent.Name
is not returning the correct value or PlayerName.Value
is empty/not equal to the player’s name. It’s also possible the value of Dogecoins is 0, so the script is working but you are not seeing any changes.
Add a print inside the if statement to make sure the code under the if is actually running. Check the console to make sure the print is being executed.
I changed some stuff up and now there’s an error:
Nil is not a valid member of Players “Players” (line 9)
local Doge = game.ServerStorage.Doge
local cost = 0
local Button = script.Parent
local Values = game.Workspace.Area1.Values
local DepositedCoins = Values.DepositedCoins
local plr = Values.PlayerName.Value
Button.Touched:Connect(function(hit)
local actualPlayer = game.Players[plr]
if hit.Parent.Name == actualPlayer then
DepositedCoins.Value += actualPlayer.Dogecoins.Value
actualPlayer.Dogecoins.Value = 0
end
end)