Hello!
Currently I am trying to make a wall that when a player hits e, a GUI pops up, asking the player if they would like to unlock the next area for a certain amount of coins. That is as far as I got, I made a local script in the text button named “Buy” that will, when a player clicks it, make the wall invisible, same for the GUI. The players coins will go down, and the player will be allowed into the next area. However, after hours of trying to fix the error, I still get the same error in the Output.
11:54:19.881 leaderstats is not a valid member of Players "Players" - Client - LocalScript:5
11:54:19.881 Stack Begin - Studio
11:54:19.881 Script 'Players.tkuski08.PlayerGui.WallPurchaces.Frame.RainForestWallFrame.Buy.LocalScript', Line 5 - Studio - LocalScript:5
11:54:19.882 Stack End
Here is the script I am using
script.Parent.MouseButton1Click:Connect(function(player)
if game.Players.leaderstats.Coins.Value >= game.Workspace.FirstWall.CostValue.Value then --"CostValue" is the IntValue
game.player.leaderstats.Coins.Value = game.player.leaderstats.Coins.Value - game.Workspace.FirstWall.CostValue.Value
game.Workspace.FirstWall.Transparency = 1
game.Workspace.FirstWall.CanCollide = false
game.Workspace.FirstWall.WhereProxIs.CanCollide = false
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Visible = false
end
end)
I had asked a friend of mine for help and we tried several different things, this script is with the IntValue that I added to the part but even without it, I get the same error.
I still have a lot to learn and I’m pretty sure this is an easy fix and I’m just thinking too hard. If anyone could help that would be great. Thanks
Okay if this is a local script, you dont need to get the player from the MouseButton1Click event. You can easily get it from Players.LocalPlayer.
Use this code for your script:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
local FirstWall = workspace:WaitForChild("FirstWall")
script.Parent.MouseButton1Click:Connect(function()
if leaderstats.Coins.Value >= FirstWall.CostValue.Value then --"CostValue" is the IntValue
leaderstats.Coins.Value -= FirstWall.CostValue.Value
FirstWall.Transparency = 1
FirstWall.CanCollide = false
FirstWall.WhereProxIs.CanCollide = false
script.Parent.Parent.Visible = false
script.Parent.Parent.Parent.Visible = false
end
end)
local plr = game.Players.LocalPlayer
local ms = plr:GetMouse()
local stat = plr:WaitForChild("leaderstats")["Coins"]
local val = plr:WaitForChild("leaderstats")["Coins"].Value
stat.Changed:Connect(function()
local text = script.Parent.PopUp.TextLabel:Clone()
text.Parent = script.Parent.PopUp
text.Name = "+".. tostring(stat.Value-val)
text.Text = "+".. tostring(stat.Value-val)
text.Rotation = math.random(-20,20)
text.Visible = true
local pos = UDim2.new(math.random(0,1000)/1000, 0,0.924, 0)
text.Position = pos
text:TweenPosition(pos-UDim2.new(0,0,1,0),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,1)
wait(1)
val = stat.Value
text:Destroy()
end)
This is the script, I believe a friend of mine made it when we started this game a while ago
I believe you should make a different topic about this. The main issue was that you were receiving that error Leaderstats not a valid member of Players, which has now been solved. This is a different issue you are dealing with, and so I suggest you make a different topic. I can help you with this other issue, but it may just be too much for just 1 topic.