Hello, I want to make a safe zone type of thing where if the player is in it, they get infinite steps, however, it is not detecting whenever the player is in it. Can someone help? Here is my current code:
local SoundRegionsWorkspace = workspace.SafeZones
local plr = game.Players.LocalPlayer
local steps = plr.PlayerGui.StepsGUI.Frame.TextLabel
local stagetrans = plr.PlayerGui.StageTransfer.CurrentStage
local overlapParams = OverlapParams.new()
overlapParams.FilterType = Enum.RaycastFilterType.Whitelist
overlapParams.FilterDescendantsInstances = { plr.Character }
local mod = script.Parent:WaitForChild('StoreSteps')
local data = require(mod)
local foundCharacter = false
for _, child in ipairs(SoundRegionsWorkspace:GetChildren()) do
if not child:IsA('BasePart') then continue end
local foundParts = workspace:GetPartsInPart(child, overlapParams)
if foundCharacter then
steps.Text = if foundCharacter then 'inf' else tostring(data[stagetrans.Text])
break
end
end
while wait() do
SoundRegionsWorkspace.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
steps.Text = "inf"
end
end)
SoundRegionsWorkspace.TouchEnded:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
steps.Text = "whatever you want them to be"
end)
end
If you want to do that I suggest make a starter player script and fire the event whenever say the torso is in the area (this depends on whether your game is r6 or r15)
Like this:
while wait() do
local Player = script.Parent.Parent
Player.Character:FindFirstChild("Torso").Touched:Connect(function(hit)
if hit.Name == "Name of the sound region" or "Other names of sound regioins" then
steps.Text = "inf"
end
end)
end
You would have to add more “or”'s for every region you want the player to have inf steps in
Also idk whether this should be a local or a normal script but you can test both. I dont think it makes a difference really
I tried optimizing your script since I couldnt access playergui with script.parent.parent no matter how many parents there were and its not working. could u tell me whats wrong?
local SafeZones = workspace.SafeZones
local plr = game.Players.LocalPlayer
local steps = plr.PlayerGui:WaitForChild("StepsGUI").Frame.TextLabel
local stagetrans = plr.PlayerGui:WaitForChild("StageTransfer").CurrentStage
local mod = script.Parent:WaitForChild('StoreSteps')
local data = require(mod)
print('loop')
while wait() do
plr.Character:FindFirstChild("Torso").Touched:Connect(function(hit)
print('touch')
if hit.Name == "sf" then
steps.Text = "inf"
else
steps.Text = tostring(data[stagetrans.Text])
end
end)
print('end')
--if steps.Text == tostring(data[stagetrans.Text]) then
-- break
end
It probably depends on where the script it. You can only use LocalPlayer if the script/localscript is in startergui, starterplayerscripts or startercharacterscripts.
Another thing. You might want Rename the mod variable. Use a capital letter. It’s showing up in blue on the devforum editor so I’m assuming it means something else.
If you let it run I’m assuming it will give you an error. What I think is happening is its waiting for one of your WaitForChild’s to find what its looking for but it doesnt exist.