Im making a sword fighting game, and I want it so if the player is on a certain block, then they are allowed to fight eachother with swords. If they are not on the block, then do not allow them to fight.
This is my script:
wait()
SafeBrickName = "SafeZone"
DefaultDistance = 30
player = script.Parent.Parent
distnum = DefaultDistance
sorted = false
function MakeFF()
if player.Character:FindFirstChild("ForceField") then
RemoveFF()
end
local ff = Instance.new("ForceField")
ff.Parent = player.Character
end
function RemoveFF()
local fc = player.Character:GetChildren()
for i = 1, #fc do
if fc[i].Name == "ForceField" then
fc[i]:Destroy()
end
end
end
while true do
sorted = false
local c = game.Workspace:GetChildren()
for i = 1, #c do
if c[i].Name == SafeBrickName and sorted == false then
distnum = DefaultDistance
local dist = (player.Character:FindFirstChild("Torso").Position - c[i].Position).magnitude
if c[i]:FindFirstChild("Distance") ~= nil then
distnum = c[i]:FindFirstChild("Distance").Value
end
if dist < distnum then
MakeFF()
sorted = true
else
if player.Character:FindFirstChild("ForceField") then
RemoveFF()
end
end
end
end
wait(3)
