Hi, i’m trying to make it so when a player wins a match they get points and then they get a win. The points are working fine since they are from a kit but the wins aren’t. heres the script that gives the points then the win after winning.
if v.Tokens then
v.Tokens.Value = v.Tokens.Value + 50
game.Players.Player.leaderstats.Wins.Value +1
end
end
break
end
Can we have a larger snippet of the code so we can know whats happening?
if not isPiggyHere then -- if isPiggyHere == false / is the piggy dead / left the game?
outcome = "piggy-left"
for i, v in pairs(contestants) do
if v.Tokens then
v.Tokens.Value = v.Tokens.Value + 50
game.Players.Player.leaderstats.Wins.Value +1
end
end
break
end
if this is what you want
It should be more of something like this
game.Players.LocalPlayer.leaderstats.Wins.Value = game.Players.LocalPlayer.leaderstats.Wins.Value + 1
Also yeah a larger snippet of the code as @dibblydubblydoo stated
this is in a script not a localscript will it still work? sorry new to scripting
Where is the script located, also can you show us even more of the script with all the variabled I can’t understand what its supposed to do
here ill just give all of the script. a good amount of it has nothing to do with this but yeah. Also it’s in serverscriptservice.
local module = {}
local status = game.ReplicatedStorage:WaitForChild(“Status”)
function module.Intermission(length)
for i = length,0,-1 do
status.Value = “Next round starts in “…i…” seconds”
wait(1)
end
end
function module.SelectChapter()
local Votes = {}
game.ReplicatedStorage.ToggleMapVote:FireAllClients(true)
for i, v in pairs(game.ReplicatedStorage.Chapters:GetChildren()) do
Votes[v.Name] = {}
end
local placeVoteConnection = game.ReplicatedStorage.PlaceVote.OnServerEvent:Connect(function(player,mapName)
if Votes[mapName] then
for i, playerVotesTab in pairs(Votes) do
for x, playerName in pairs(playerVotesTab) do
if playerName == player.Name then
table.remove(playerVotesTab,x)
break
end
end
end
table.insert(Votes[mapName],player.Name)
game.ReplicatedStorage.UpdateVoteCount:FireAllClients(Votes)
end
end)
game.ReplicatedStorage.MapVoting.Value = true
wait(15)
game.ReplicatedStorage.MapVoting.Value = false
game.ReplicatedStorage.ToggleMapVote:FireAllClients(false)
placeVoteConnection:Disconnect()
local mostVotes = nil
local mostVoted = nil
for i, mapTable in pairs(Votes) do
local votes = #mapTable
if mostVotes == nil then
mostVotes = votes
mostVoted = i
else
if votes >= mostVotes then
mostVotes = votes
mostVoted = i
end
end
end
local chosenChapter
if mostVotes == nil or mostVoted == nil then
chosenChapter = game.ReplicatedStorage.Chapters:GetChildren()[math.random(1,#game.ReplicatedStorage.Chapters:GetChildren())]
else
chosenChapter = game.ReplicatedStorage.Chapters[mostVoted]
end
status.Value = chosenChapter.Name.." has been selected with "..tostring(mostVotes)
wait(5)
return chosenChapter
end
function module.ChoosePiggy(players)
local RandomObj = Random.new()
local chosenPiggy = players[RandomObj:NextInteger(1,#players)]
return chosenPiggy
end
function module.DressPiggy(piggy)
local character
if piggy.EquippedSkin.Value ~= "" then
if game.ReplicatedStorage.Skins:FindFirstChild(piggy.EquippedSkin.Value) then
character = game.ReplicatedStorage.Skins[piggy.EquippedSkin.Value]:Clone()
end
else
character = game.ReplicatedStorage.Skins.Piggy:Clone()
end
character.Name = piggy.Name
piggy.Character = character
character.Parent = workspace
end
function module.TeleportPiggy(player)
if player.Character then
player.Character.Humanoid.WalkSpeed = 14
local bat = game.ServerStorage.Tools.PiggyBat:Clone()
bat.Parent = player.Character
if player.Character:FindFirstChild("HumanoidRootPart") then
player.Character.HumanoidRootPart.CFrame = game.Workspace.WaitingRoom.PiggyWaitingSpawn.CFrame + Vector3.new(0,5,0)
end
local TrapCount = Instance.new("IntValue")
TrapCount.Name = "TrapCount"
TrapCount.Value = 5
TrapCount.Parent = player
game.ReplicatedStorage.ToggleTrap:FireClient(player,true)
end
end
function module.TeleportPlayers(players, mapSpawns)
– ‘players’ will be a Table containing all contestants’ player objects
– eg {game.Workspace.Alvin_Blox, game.Workspace.Shedletsky, game.Workspace.Naco88}
for i, player in pairs(players) do
if player.Character then
local character = player.Character
if character:FindFirstChild("HumanoidRootPart") then
player.Character.Humanoid.WalkSpeed = 16
local rand = Random.new()
player.Character.HumanoidRootPart.CFrame = mapSpawns[rand:NextInteger(1,#mapSpawns)].CFrame + Vector3.new(0,10,0)
local hitboxClone = game.ServerStorage.Hitbox:Clone()
hitboxClone.CFrame = character.HumanoidRootPart.CFrame
local weld = Instance.new("Weld")
weld.Part1 = character.HumanoidRootPart
weld.Part0 = hitboxClone
weld.Parent = character
hitboxClone.Parent = player.Character
end
end
end
end
function module.InsertTag(contestants,tagName)
for i, player in pairs(contestants) do
local Tag = Instance.new(“StringValue”)
Tag.Name = tagName
Tag.Parent = player
end
end
local function toMS(s)
return (“%02i:%02i”):format(s/60%60, s%60) – 600 → 10:00
end
function module.StartRound(length,piggy,chapterMap) – length (in seconds)
local outcome
game.ServerStorage.GameValues.GameInProgress.Value = true
for i = length,0,-1 do
if i == (length - 20) then
module.TeleportPlayers({piggy},chapterMap.PlayerSpawns:GetChildren())
status.Value = "Piggy has woken up!"
wait(2)
end
local contestants = {}
local isPiggyHere = false
local Escapees = 0
for i, player in pairs(game.Players:GetPlayers()) do
if player:FindFirstChild("Contestant") then
table.insert(contestants,player)
elseif player:FindFirstChild("Piggy") then
isPiggyHere = true
end
if player:FindFirstChild("Escaped") then
Escapees = Escapees + 1
end
end
status.Value = toMS(i)
if Escapees > 0 then
outcome = "escaped"
for i, v in pairs(contestants) do
if v.Tokens then
v.Tokens.Value = v.Tokens.Value + 50
end
end
break
end
if not isPiggyHere then -- if isPiggyHere == false / is the piggy dead / left the game?
outcome = "piggy-left"
for i, v in pairs(contestants) do
if v.Tokens then
v.Tokens.Value = v.Tokens.Value + 50
end
end
break
end
if #contestants == 0 then
outcome = "piggy-killed-everyone"
break
end
if i == 0 then
outcome = "time-up"
break
end
wait(1)
end
if outcome == "piggy-killed-everyone" then
status.Value = "The Piggy Has Killed Everyone"
elseif outcome == "time-up" then
status.Value = "Time Up - Contestants Win"
elseif outcome == "piggy-left" then
status.Value = "Piggy has died / left! Contestants win!"
elseif outcome == "escaped" then
status.Value = "Contestants have escaped! Piggy loses!"
end
wait(5)
end
function module.RemoveTags()
game.ServerStorage.GameValues.GameInProgress.Value = false
game.ReplicatedStorage.ToggleCrouch:FireAllClients(false)
for i, v in pairs(game.Players:GetPlayers()) do
if v:FindFirstChild("Piggy") then
v.Piggy:Destroy()
if v.Backpack:FindFirstChild("PiggyBat") then v.Backpack.PiggyBat:Destroy() end
if v.Character:FindFirstChild("PiggyBat") then v.Character.PiggyBat:Destroy() end
if v:FindFirstChild("TrapCount") then
v.TrapCount:Destroy()
end
game.ReplicatedStorage.ToggleTrap:FireClient(v,false)
v:LoadCharacter()
elseif v:FindFirstChild("Contestant") then
v.Contestant:Destroy()
for _, p in pairs(v.Backpack:GetChildren()) do
if p:IsA("Tool") then
p:Destroy()
end
end
for _, p in pairs(v.Character:GetChildren()) do
if p:IsA("Tool") then
p:Destroy()
end
end
end
if v:FindFirstChild("Escaped") then
v.Escaped:Destroy()
end
end
end
return module
You can’t change leaderstats values inside a localscript, so the script should be reverted to a normal one.
Actually you can.
Just the change won’t reflect on the server.
Then there is no point, the leaderstats has to reflect on the server. It is best if OP changes it in a server script or fire a remote event.
its already a normal script so am I fine?
You can make the localscript fire remote function to make change on the server
Sorry, was talking to the other dude, localPlayer can only be accessed in a localscript so the output would return nil as a localplayer does not exist in serverscripts.
Literally only, otherwise through a remote you can get the local player who fired the event.
@ItzGpYt
Whenever a person wins the match, just increment their value on the server.
local player = -- get the player who won, as from your current implementation,
local object = player.leaderstats.Wins
object.Value = object.Value + 1
I don’t really know how I would go about doing this though…
Is there any way I could just add that script right where I was doing the script?
Can you point out where the script for a player winning is?
this is the script that plays right after a player wins (it works other than the win part of course)
if v.Tokens then
v.Tokens.Value = v.Tokens.Value + 50
game.Players.Player.leaderstats.Wins.Value +1
end
end
break
end
How is Player defined? It looks like you’re trying to find someone specifically named “Player” in the game. This won’t increase anyone’s Win value.
Do this
if Escapees > 0 then
outcome = "escaped"
for i, v in pairs(contestants) do
if v.Tokens then
v.Tokens.Value = v.Tokens.Value + 50
v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1--add win
end
end
break
end
if not isPiggyHere then -- if isPiggyHere == false / is the piggy dead / left the game?
outcome = "piggy-left"
for i, v in pairs(contestants) do
if v.Tokens then
v.Tokens.Value = v.Tokens.Value + 50
v.leaderstats.Wins.Value = v.leaderstats.Wins.Value + 1--add win
end
end
break
end
EDIT: This should work I’m not sure how leaderstats is defined in your script so you look through that