So when I find a player in the servescript and change one of their values like leaderstats, it changes for all of the players?
Start of the script=
game.Players.PlayerAdded:Connect(function(plr)
local rp = game:GetService("ReplicatedStorage")
local event = rp.Rebirth
local player = plr.Character
local othersutff = plr:WaitForChild("OtherStuff")
local rebirth = othersutff.rebirths
local rebirthcost = plr.OtherStuff.rebirthcost
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats.Cash
local wood =leaderstats.Wood
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Cash = Instance.new("IntValue")
Cash.Name = "Cash"
Cash.Parent = leaderstats
-- Follow the same proccess for making other values
Now all you need to do is whenever the player does something, like killing another player. You need to get the player instance and just do something like:
-- Specified the player instance
plr.leaderstats.Cash.Value = 100
Just to make sure all i need to do is plr.leaderstats.cash.Value += instad of cash.value +=?
Here is the full code:
game.Players.PlayerAdded:Connect(function(plr)
local rp = game:GetService(“ReplicatedStorage”)
local event = rp.Rebirth
local player = plr.Character
local othersutff = plr:WaitForChild("OtherStuff")
local rebirth = othersutff.rebirths
local rebirthcost = plr.OtherStuff.rebirthcost
local leaderstats = plr:WaitForChild("leaderstats")
local cash = leaderstats.Cash
local wood =leaderstats.Wood
event.OnServerEvent:Connect(function()
print(cash.Value)
print(rebirthcost.Value)
if tonumber(cash.Value) >= tonumber(rebirthcost.Value) then
rebirthcost.Value *= 2
rebirth.Value += 0.1
math.ceil(rebirth.Value)
math.ceil(rebirthcost.Value)
cash.Value = 0
wood.Value = 0
print(rebirth.Value)
else
print("not enough money")
end
end)
rp.Convert.OnServerEvent:Connect(function()
if plr.axes.twxCash.Value == true then
cash.Value += wood.Value * rebirth.Value * 2
wood.Value = 0
else
cash.Value += wood.Value * rebirth.Value
wood.Value = 0
end
end)
local RS = game:GetService("ReplicatedStorage")
local AddWoodEvent = RS.AddWood
local DamageValue = 0
local function updatedamg(idk: NumberValue)
local Character = plr.Character or plr.CharacterAdded:Wait()
local Axe = plr.Character:WaitForChild("Axe")
local idk = Axe:FindFirstChild("damage").Value
print(idk)
return idk
end
AddWoodEvent.OnServerEvent:Connect(function(Player)
DamageValue = updatedamg(DamageValue)
if not DamageValue then warn("Axe has no damage value") return end
local PlayerAxes = Player:WaitForChild("axes", 5)
if not PlayerAxes then warn("Player has no axes") return end
local twxWood = PlayerAxes:FindFirstChild("twxWood", 5)
print(DamageValue)
wood.Value += DamageValue * (twxWood.Value and 2 or 1)
DamageValue = 0
end)
rp.Cleartools.OnServerEvent:Connect(function()
for _, child in pairs(plr.Character:GetChildren()) do
if child:IsA("Tool") then
child:Destroy()
end
end
for _, child in pairs(plr.Backpack:GetChildren()) do
if child:IsA("Tool") then
child:Destroy()
end
end
task.wait()
end)
rp.Areas.Forest.OnServerEvent:Connect(function(plr)
if cash.Value >= 5000 then
plr.axes.Forest.Value = true
cash.Value -= 500
rp.Areas.sendForest:FireClient(plr)
else
return
end
end)
rp.Areas.Farm.OnServerEvent:Connect(function(plr)
if cash.Value >= 50000 then
plr.axes.Farm.Value = true
cash.Value -= 50000
rp.Areas.sendFarm:FireClient(plr)
else
return
end
end)
I see your problem now. On some of your serverevents for your remote event you aren’t using the player instance that is returned in the parameters.
local rebirthcost = plr.OtherStuff.rebirthcost
local leaderstats = plr:WaitForChild("leaderstats")
This isn’t the same player instance as the player who has done the action that has fired the remote event to the server. Also, it’s probably because you have these server events inside of that playeradded event. A playeradded event is supposed to only run when the player is added. Put those remote events outside of the playeradded event.
Even in the server events where you do put in the plr instance into the parameters. You don’t use them, you instead use the variables you made. Here’s an example of how you would fix one of your things.
rp.Areas.Forest.OnServerEvent:Connect(function(plr)
if plr.leaderstats.cash.Value >= 5000 then
plr.axes.Forest.Value = true
plr.Cash.Value -= 500
rp.Areas.sendForest:FireClient(plr)
else
return
end
end)
And do this outside of your playeradded event so you don’t accidently muddle up the player instances.
If i put them out of the playeradded event then I will not get the plr and is the whole reason i added player added event is to find the player in a serverscript.
rp.Areas.Forest.OnServerEvent:Connect(function(plr)
local leaderstats = plr.leaderstats
end)
In that code above, you can see I’m getting the specific player instance. When you fire a remote event, it returns the player instance that fired it. So that’s how you can use it and you can figure out which player did it Booooom.
Thanks, I have one more question, so whenever the player clciks on the button it says the player does not own forest but gets teleports to it? This is on players who i have tested to try to bug fix it on so it might be because the players are bugged or idk?
local TeleportPart1 = workspace:WaitForChild("ring2").Part
script.Parent.MouseButton1Click:Connect(function(plr)
local w = game.Players.LocalPlayer:WaitForChild("axes").Forest
if w.Value == true then
game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = TeleportPart1.CFrame + Vector3.new(0, 5, 0)
else
game.ReplicatedStorage.Areas.Forest:FireServer(plr)
end
end)
Not sure what you mean but I don’t think this line of code would run because you are using the + operator and a Vector3 on a cframe. If you’re getting the cframe of the HRP then you should use cframes only. Like this