hello fellow developers! i want to change my leaderstats value but there is a problem HERE IS THE CODE :
local function leaderboardSetup(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Gold"
wins.Value = 0
wins.Parent = leaderstats
local part = game.Workspace.Part
if part.ClickDetector.MouseClick:Connect(function() then
wins.Value = wins.Value + 1
end
end
-- Connect the "leaderboardSetup()" function to the "PlayerAdded" event
Players.PlayerAdded:Connect(leaderboardSetup)
OUTPUT :
ServerScriptService.Script:14: Expected identifier when parsing expression, got 'then' - Studio - Script:14
A click detector is an event just like how “playerAdded” is an event. You would need to put the click detector as a separate function outside the player added function and then adjust the win value.
local part = partlocation
function Clicked(player)
local wins = player:FindFirstChild(“leaderstats”).Gold
if wins then
wins.value += 1
end
end)
part.MouseClick:Connect(Clicked)
Sorry if the code errors or ive made a mistake, i’m currently typing this on phone.
Exactly what Lev above me has said is true. To simplify it, all you would have to do is remove the if word and put a bracket on the end of the end. You would also have to change the player reference using the click detector. The .MouseClick event provides you with the player that clicked. As you can see in the brackets, I have placed the word player there. That just lets me reference that player.
LIke this:
if part.ClickDetector.MouseClick:Connect(function(player)
player.Leaderstats.Wins.Value += 1
end