Hello,
I’m making a tag game. Right now, everything is functioning correctly, but because of the lag between the server and clients, players are able to tag each other when it looks like they are still far away on the client screen.
Here is my code. Instead of the person being “it,” there’s one person who has the Midas Touch and are colored gold. When you tag them, you take their gold color and start earning points.
game.Players.PlayerAdded:Connect(function(Player)
Player:SetAttribute("Merked", false)
Player:SetAttribute("Playing", false)
Player:SetAttribute("PastMenu", false)
Player.CharacterAdded:Connect(function(Char)
local cr = crown:Clone()
cr.Parent = Char
cr.Position = Char.Head.Position + Vector3.new(0,2,0)
local w = Instance.new("Weld")
w.Part0 = Char.Head
w.Part1 = cr
w.Parent = Char.Head
w.C0 = CFrame.new(0,2,0)
Char.HumanoidRootPart.Touched:Connect(function(touched)
if touched.Parent:FindFirstChild("Humanoid") and touched.Parent:GetAttribute("Midasable") == true and deb == false and touched.Parent:FindFirstChild("Humanoid").Health > 0 and Char:GetAttribute("Midas") == true then
deb = true
Char:SetAttribute("Midas", false)
Char.Crown.Transparency = 1
Char.Highlight:remove()
alreadySubtracting = true
game.SoundService.ping:Play()
local highlight = Instance.new("Highlight", touched.Parent) -- Set the character variable to the character model of the targeted player
highlight.Adornee = touched.Parent
highlight.FillColor = Color3.new(1, 0.788235, 0.14902)
highlight.FillTransparency = .2
highlight.OutlineColor = Color3.new(1, 0.976471, 0.294118)
touched.Parent:SetAttribute("Midas", true)
touched.Parent.Crown.Transparency = 0
touched.Parent:SetAttribute("Powered", false)
adding = true
for _, pw in game.Workspace[game.Workspace.GameManagement.MapSelection.Value]:GetChildren() do
if pw.Name == "PowerUp" then
if pw.Rval.Value == touched.Parent.Name then
pw.Rval.Value = ""
pw.PowerPlat.Color = Color3.new(1, 0.666667, 0)
game.ReplicatedStorage.PWUsed:FireClient(game.Players[touched.Parent.Name])
end
end
end
Player.PlayerGui.Throw.Enabled = false
game.Workspace.GameManagement.ArrowTargetName.Value = touched.Parent.Name
wait(.5)
deb = false
end
end)
while true do
wait(1)
if Char:GetAttribute("Midas") == true and game.Workspace.GameManagement.GameActive.Value == true then
Player.leaderstats.Points.Value += 1
end
end
end)
end)
I’m familiar with the concept of lag compensation when it comes to FPS games, and I can imagine it’s about creating local scripts that then send the information to the server once a hit is confirmed on your client. If you were to aim at a player on your screen, it would register the hit because your cursor is on top of them on your screen. You wouldn’t be able to tell whether you actually got hit on the receiving end because it happens so fast.
But how would something like this work when you need to physically tag another player? If I’m trying to tag another player, there is no issue because I already have to have contact with them on my client, but if that person then turns to try and tag me, it looks like they can do so from much further away on my screen.
Any ideas of how I could try to resolve this?