"Ball is not a valid member of StringValue "Players.BlueClothesPerson.leaderstats.Ball"

I keep getting an error saying: Ball is not a valid member of StringValue “Players.BlueClothesPerson.leaderstats.Ball”

Things I've tried

I have tried changing leaderstat.Ball.Value = "Default" to leaderstat.Ball.StringValue = "Default", and searching on the dev forums for any-one who had any similar problems.

Script(s)

Button to give the ball

local Case = script.Parent.Parent
local ClickDetector = script.Parent
local Ball = game.ServerStorage.Default --> Change Default to ball name.. <--
local ClickSound = game.ReplicatedStorage.GloveGot

-- Actual Script

ClickDetector.MouseClick:Connect(function(plr)
	local leaderstat = plr.leaderstats.Ball
	ClickSound:Play()
	leaderstat.Ball.Value = "Default"
end)

Leaderstats/Leaderboard

local Players = game:GetService("Players")
local INTvalue = Instance.new("IntValue")

local function leaderboardSetup(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local Punches = Instance.new("IntValue")
	Punches.Name = "Smacks"
	Punches.Value = 0
	Punches.Parent = leaderstats
	
	local Ball = Instance.new("StringValue")
	Ball.Name = "Ball"
	Ball.Value = "Default"
	Ball.Parent = leaderstats
end

Players.PlayerAdded:Connect(leaderboardSetup)

Any help is appreciated

1 Like
local Case = script.Parent.Parent
local ClickDetector = script.Parent
local Ball = game.ServerStorage.Default --> Change Default to ball name.. <--
local ClickSound = game.ReplicatedStorage.GloveGot

-- Actual Script

ClickDetector.MouseClick:Connect(function(plr)
	local leaderstat = plr.leaderstats
	ClickSound:Play()
	leaderstat.Ball.Value = "Default"
end)
2 Likes

Your leaderstat name in the actual script does not have the same name as your leaderstats folder which you define below:

EDIT: Nevermind I can’t read. I didn’t realize that there was a variable defining it.

(Generally good practice to keep all names the same when creating variables to represent element/values)

Looks like @lV0rd beat me to it, but your leaderstat variable has .Ball after it.

At the end of the function:

This is trying to look for plr.leaderstats.Ball.Ball.Value which doesn’t exist.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.