You can write your topic however you want, but you need to answer these questions:
- What do you want to achieve? Keep it simple and clear!
I am trying to make my king of the hill system have the flags tween down when one 1 player is on it but when multiple come on it pauses the tween until one guy leaves again it resumes.
- What is the issue? Include screenshots / videos if possible!
The issue occurs when the second player joins the pad. It the output is printing “pausing tween” so it is reading that there are multiple people on it but the tween does not pause even though I call the pause method. I assume it is something to do with using runService but can not find any issue or errors.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried many different methods but they give me the same issue and can not figure out why it is working.
here is my code
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local DataManager require(game:GetService("ServerScriptService"):WaitForChild("Modules").DataManager)
local FlagParts = workspace:WaitForChild("Flags/King Of The Hill").FlagParts
local FlagModels = workspace:WaitForChild("Flags/King Of The Hill").FlagModels
local FlagPositions = {
Down = {Flag1 = Vector3.new(-54.348, 103.035, 298.019)};
Up = {Flag1 = Vector3.new(-54.348, 120.375, 298.019)};
}
local ZonePlus = require(game:GetService("ServerScriptService"):WaitForChild("Modules").ZonePlus)
local ZoneService = require(ZonePlus.ZoneService)
local PlayerInside = {Flag1 = false}
local NumOfPlayersTouching = {Flag1 = 0}
for _,part in pairs(FlagParts:GetChildren()) do
local zone = ZoneService:createZone(part.Name.."Zone", part, 15)
zone.playerAdded:Connect(function(player)
NumOfPlayersTouching[part.Name] = NumOfPlayersTouching[part.Name] + 1
if NumOfPlayersTouching[part.Name] > 1 then
PlayerInside[part.Name] = false
else
PlayerInside[part.Name] = player.Name
end
end)
zone.playerRemoving:Connect(function(player)
NumOfPlayersTouching[part.Name] = NumOfPlayersTouching[part.Name] - 1
if NumOfPlayersTouching[part.Name] > 1 then
PlayerInside[part.Name] = false
else
PlayerInside[part.Name] = player.Name
end
end)
zone:initLoop()
end
RunService.Stepped:Connect(function()
for _,part in pairs(FlagParts:GetChildren()) do
local UIPart = FlagModels[part.Name].FlagModel.UIPart
local tween = TweenService:Create(UIPart, TweenInfo.new(15), {Position = FlagPositions.Down[part.Name]})
if PlayerInside[part.Name] ~= false then
if part.CurrentLeader.Value ~= PlayerInside[part.Name] then
tween:Play()
part.CurrentLeader.Value = PlayerInside[part.Name]
UIPart.UI1.Enabled = false
UIPart.UI2.Enabled = false
end
else
print("pausing tween")
tween:Pause()
end
tween:Destroy()
end
end)