I am making one of those “sword fight and steal peoples time games”, and I made a script to steal peoples time, but it doesn’t work
This is a server script
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
local victimtime = plr:WaitForChild("leaderstats").Time
if humanoid:FindFirstChild("creator") then
local tag = humanoid.creator
local killer = game.Players:WaitForChild(tag.Value)
local killertime = killer:WaitForChild("leaderstats").Time
killertime.Value = killertime.Value + victimtime.Value
victimtime.Value = 0
else
victimtime.Value = 0
end
end)
end)
end)
That’s not how tags work, you would need to use CollectionService or get all the tags in the instance. So something like this:
local PartTags = workspace.YourHumanoid:GetTags()
for i,v in pairs(PartTags) do
if v == "YourTag" then
print("Tag found: "..v)
end
end
or
local Part = --Your Part
local CollectionService = game:GetService("CollectionService")
if CollectionService:HasTag(Part, "YourTag") then
print("Found tag: YourTag")
end
EDIT:
Scrap that, I just realised its a value. I also made a more robust version, if you don’t mind:
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local humanoid = char:WaitForChild("Humanoid")
if not plr:FindFirstChild("leaderstats") then
warn("No leaderstats found for player: " .. plr.Name)
return
end
local victimTimeValue = plr.leaderstats:FindFirstChild("Time")
if not victimTimeValue then
warn("No Time value found in leaderstats for: " .. plr.Name)
return
end
humanoid.Died:Connect(function()
local creatorTag = humanoid:FindFirstChild("creator")
if creatorTag then
local success, killer = pcall(function()
return game.Players:GetPlayerByUserId(creatorTag.Value)
end)
if success and killer then
if killer:FindFirstChild("leaderstats") then
local killerTimeValue = killer.leaderstats:FindFirstChild("Time")
if killerTimeValue then
killerTimeValue.Value = killerTimeValue.Value + victimTimeValue.Value
victimTimeValue.Value = 0
end
end
else
victimTimeValue.Value = 0
end
else
victimTimeValue.Value = 0
end
end)
end)
end)
How are you incrementing the time’s value? Make sure that you’re not incrementing the time on the client, since it won’t change on the server-side
(I’m aware that the script you’ve provided is a server script, I’m talking about the script you’re using to increment the time while the game is active, not when someone is killed)
creatorTag is an ObjectValue, not an NumberValue or IntValue.
The OP is using a classic sword, inside the script, this is how the tagging works:
function TagHumanoid(humanoid, player)
local Creator_Tag = Instance.new("ObjectValue")
Creator_Tag.Name = "creator"
Creator_Tag.Value = player
Debris:AddItem(Creator_Tag, 2)
Creator_Tag.Parent = humanoid
end
function UntagHumanoid(humanoid)
for i, v in pairs(humanoid:GetChildren()) do
if v:IsA("ObjectValue") and v.Name == "creator" then
v:Destroy()
end
end
end
Here, the creatorTag is ObjectValue, and its value is a Player. So in your code, killer should creatorTag.Value.