The reason for the flashing is because you're using TouchEnded and Touched. What will happen is you'll have a character that will walk around and every time their feet hit the ground on the spawn the GUI will be enabled, and every time their feet leave the ground it will be turned off. This will lead to the flashiness when you're walking.
To solve this you could use a few methods...
##Magnitude
You could constantly check the player's magnitude in relation to the spawn part to see if they have gone outside of it's area or not.
Due to magnitude's properties you can use the x & z components of the position to tract a circular shape around your spawn, or you could add in the y component to track a 3D spherical shape. Here is an example...
local safeZones = CollectionService:GetTagged("SafeZone")
function trackCharacter(character)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
while true do
wait(0.1)
local insideSafeZone = false
for i,v in pairs(safeZones) do
if (v.Position - humanoidRootPart.Position).Magnitude <= v:GetExtentsSize() then
insideSafeZone = true
end
end
if insideSafeZone then
else
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
trackCharacter(character)
end)
end)
It is also recommended you turn your GUI's property ResetOnSpawn to false. It saves you a lot of trouble redefining it in your scripts.
Other methods could include Region3, or simply checking part sizes/positions in comparison to player's
Example of that...
local safeZones = CollectionService:GetTagged("SafeZone")
function trackCharacter(character)
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
while true do
wait(0.1)
local insideSafeZone = false
for i,v in pairs(safeZones) do
if (humanoidRootPart.Position.X < v.Position.X +v.Size.X/2) then
if (humanoidRootPart.Position.X > v.Position.X - v.Size.X/2) then
if (humanoidRootPart.Position.Z < v.Position.Z + v.Size.Z/2) then
if (humanoidRootPart.Position.Z > v.Position.Z - v.Size.Z/2) then
insideSafeZone = true
end
end
end
end
end
if insideSafeZone then
else
end
end
end
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(character)
trackCharacter(character)
end)
end)
I used PlayerAdded events just to make it look a bit easier to read, but you'd likely do this in a local script if you're ONLY messing around with GUIs. In the local script the event catches would look more like this...
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
function trackCharacter(character)
...
end
spawn(function()
trackCharacter(character)
end)
player.CharacterAdded:Connect(function(newCharacter)
character = newCharacter
trackCharacter(character)
end)
1 comment
It didn't work, just tried it, I'm gonna post the script I made after what you gave me.