So i'm making a wave defense game based on piggy characters and the round mechanic works perfectly but i'm trying a safe zone for the lobby so when the players are in the lobby the rounds won't start until they get out. I made a part that is around the entire lobby and named it SafePart but i'm new to studio so idk how to script it so the guis and the spawners won't work until the player is out of the SafePart. (The model for the wave defense is My Wave Defense Kit(pls don't steal) by jaydonashford and it was made in the 18/12/2024 at 11pm. thx for helping it will help me to learn scripting a lot and save me a lot of time 😄
#Safe zone question
1 messages · Page 1 of 1 (latest)
Part.Touched and Part.TouchEnded
** You are now Level 1! **
When touched you enable the safezone effect and TouchEnded you disable it
part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
end)
K i will try it
But how do i make like the safe zone effect
Like if the player is in the safe zone i disable the round script ?
You just check if he's in the safe zone in the round script
Like if you want to prevent someone from damaging another in Safe Zone, you can check if the player is in/out of a Safe Zone before applying the damage.
Script I made quickly in ServerScriptService:
local CollectionService = game:GetService("CollectionService")
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local SafeZoneList = CollectionService:GetTagged("SafeZone")
local SafeZoneData = {}
for _, ZonePart: Part in SafeZoneList do
SafeZoneData[ZonePart] = {Players = {}, Loops = {}}
ZonePart.Touched:Connect(function(TouchedPart)
local Character = TouchedPart:FindFirstAncestorOfClass("Model")
local Player = Character and Players:GetPlayerFromCharacter(Character)
if Player ~= nil and not SafeZoneData[ZonePart].Players[Player.UserId] then
Player:AddTag("InSafeZone")
SafeZoneData[ZonePart].Players[Player.UserId] = true
SafeZoneData[ZonePart].Loops[Player.UserId] = RunService.Heartbeat:Connect(function()
local HitList = workspace:GetPartBoundsInBox(ZonePart.CFrame, ZonePart.Size)
if Character and not table.find(HitList, Character.PrimaryPart) then
SafeZoneData[ZonePart].Players[Player.UserId] = nil
Player:RemoveTag("InSafeZone")
SafeZoneData[ZonePart].Loops[Player.UserId]:Disconnect()
end
end)
end
end)
end
You'll have to set-up a BasePart with a tag named "SafeZone"
@mighty hawk
SetProperty for the player for that no need fot exsessive tables n other
Wdym by SetProperty?
I need to use a table to store the RBXScriptConnection
This function doesn't exists?
I know about :SetAttribute and :AddTag
But not :SetProperty
That doesn't change anything, using Tag is same
I messed it up with another thingy mb
Np
Yes
I havn't tried but I'm almost 100% sure that it sucks
Idk the docs said whenever the colision stops with the part it fires
Since roblox has a check for that
I'd test it if i was at my computer rn but cant
K thx i will try that
I think i can script that
local InSafezone = false
safezone.Touched:Connect(function(hit)
if not InSafezone then
InSafezone = true
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
print("In safezone!")
end
end)
safezone.TouchEnded:Connect(function(hit)
if InSafezone then
InSafezone = false
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
print("Out of safezone!")
end
end)```
done
it works i tested it
just slap in your tag and chech it instead of the variable
check*
With the wave defense kit?
Or is it like for people to not hurt each other
how do i do that
Player:RemoveTag("InSafeZone") and Player:AddTag
K
Wait one sec where do i put that
In the thing i want to work with right?
I'm gonna try thx for helping everyone
safezone.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not player:HasTag("InSafeZone") then
player:AddTag("InSafeZone")
print("In safezone!")
end
end)
safezone.TouchEnded:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player:HasTag("InSafeZone") then
player:RemoveTag("InSafeZone")
print("Out of safezone!")
end
end)```
this
it's a server script under the safezone part btw
K
Wow TouchEnded actually works, I always thought it wasn't working
Games that uses Touched seemed to not working properly like the lava in BloxFruits
But ig they just don't use TouchEnded
Oh ok
Also if you want the SafeZone to work even in wierd positions like this...
Yeah?
...you'll need to check if the "hit" part is the HumanoidRootPart
Thanks to Veltrixion
👋
dude it works with any pos
the same script i provided
works with any part and is accurate instead of using just the humanoid root part
safezone.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and not player:HasTag("InSafeZone") then
player:AddTag("InSafeZone")
print("In safezone!")
end
end)
safezone.TouchEnded:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player and player:HasTag("InSafeZone") then
player:RemoveTag("InSafeZone")
print("Out of safezone!")
end
end)```
If you have something like a breathing animation, since the parts are all effecting the Tag, if a limb goes outside of the zone, the Tag will be removed even that the player is still in.