Hey devs,
So I have a safezone script and right now what is happening is my dash function and safezone are clashing, creating a broken safezone.
Basically, everything is fine, until when the dash happens, and then it breaks, thinking that the player left the safezone. The dash function uses ‘LinearVelocity’
Here is my code: (under a part in the workspace)
local Safezone = script.Parent
local processingPlayers = {}
local function isPushedByLinearVelocity(character)
local rootPart = character:FindFirstChild("HumanoidRootPart")
if rootPart then
for _, child in rootPart:GetChildren() do
if child:IsA("LinearVelocity") and child.Enabled then
return true
end
end
end
return false
end
Safezone.Touched:Connect(function(hit)
local character = hit.Parent
if character and character:IsDescendantOf(game.Workspace) and character.Parent == game.Workspace then
if not processingPlayers[character] then
processingPlayers[character] = true
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.MaxHealth = math.huge
humanoid.Health = math.huge
end
wait(0.1)
processingPlayers[character] = false
end
end
end)
Safezone.TouchEnded:Connect(function(hit)
local character = hit.Parent
if character and character:IsDescendantOf(game.Workspace) and character.Parent == game.Workspace then
if not processingPlayers[character] and not isPushedByLinearVelocity(character) then
processingPlayers[character] = true
local player = game.Players:GetPlayerFromCharacter(character)
if player then
local statsFolder = player:FindFirstChild("Stats")
if statsFolder then
local defensePoints = statsFolder:FindFirstChild("DefensePoints")
if defensePoints then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.MaxHealth = 100 + defensePoints.Value
humanoid.Health = 100 + defensePoints.Value
end
end
end
end
wait(0.1)
processingPlayers[character] = false
end
end
end)
And yes, it does function properly, even with that function.
Thanks for your help!
1 Like
Still needing assistance with this script. If you need, I can provide the dash script.
1 Like
Well from what I can see, you ignore the player if they are dashing when they leave. (As far as I can tell.)
2 Likes
Yes, but what is happening is that it is thinking they left but they didn’t.
Can you fix it with a script?
1 Like
Wait this might not even have to do with the dash, since I see the processingPlayers[character] = false, unless this is needed for something. Although I’d recommend using task.wait, since it doesn’t throttle.
3 Likes
So, what should I do? I’m confused on what you are trying to tell me.
1 Like
Well I’m wondering if it’s a debounce issue to do with setting the character being processed true/false, or just Roblox being wonky with touch events. If it’s the second case I would use something like ZoneService.
1 Like
Okay, can you give me an example script of what I could fix?
Don’t want to have to migrate my scripts over.
Well if it’s the first case, then I’d probably just remove the processing false line from the first function, and then in the touched ends function change it to check if the character value is true (and subsequently just set the character value in the table to false).
The caveat though is that touch ended has always been wonky
Again, can I have an example script? It’s hard to understand what you mean with just text. Supply a script, even a little chunk of code before replying again.
something like this? no guarantee it’d work unfortunately
local Safezone = script.Parent
local safePlayers = {}
local function isPushedByLinearVelocity(character)
--not gonna touch this since idk how the dash works
end
Safezone.Touched:Connect(function(hit)
local character = hit.Parent
if character and character:IsDescendantOf(game.Workspace) and character.Parent == game.Workspace then
if not safePlayers[character] then
safePlayers[character] = true
--rest goes here
end
end
end)
Safezone.TouchEnded:Connect(function(hit)
local character = hit.Parent
if character and character:IsDescendantOf(game.Workspace) and character.Parent == game.Workspace then
if safePlayers[character] and not isPushedByLinearVelocity(character) then
safePlayers[character] = false
--rest of the function
end
end
end)
2 Likes
fair enough lol, sometimes I’m not entirely clear about stuff and don’t know until someone points it out
1 Like