IN the Barrier field section when i make the barrier i sometimes spawn outside of it. Also, sometimes the cooldown for Enabled doesnt work and i am able to make the barrier either an extra time, extra two times, or endlessly make them. I need to help to fix this. Also, plz give me suggestions on how i can make this barrier much much better and look professional.
Here is the script. Dont mind the barrier section. ONLY THE BARRIER FIELD SECTION!!!
local Tool = script.Parent
Player = game.Players.LocalPlayer
local mouse = Player:GetMouse()
char = Player.Character
hum = char.Humanoid
root = char.HumanoidRootPart
local UIS = game:GetService("UserInputService")
local RemoteEvent = Tool.RemoteEvent
local Enabled = true
local en = true
Tool.Activated:connect(function()
if not en then return end
en = false
wait(2)
en = true
end)
local Debounce = false
UIS.InputBegan:Connect(function(Input)
if Input.KeyCode == Enum.KeyCode.Q then
if Debounce == true then return end
Debounce = true
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://1146690806"
Sound.PlaybackSpeed = 1
Sound.MaxDistance = 100000
Sound.Volume = 10
Sound.Parent = char.HumanoidRootPart
Sound:Play()
RemoteEvent:FireServer(Debounce)
wait(2)
Debounce = false
end
end)
mouse.KeyDown:Connect(function(key)
if Enabled == false then return end
key = key:lower()
if key == "e" then
Enabled = false
local Sound = Instance.new("Sound")
Sound.SoundId = "rbxassetid://2394905313"
Sound.Volume = 10
Sound.PlaybackSpeed = 1
Sound.MaxDistance = 10000
Sound.Parent = char.HumanoidRootPart
Sound:Play()
local BarrierField = Instance.new("Part")
BarrierField.BrickColor = BrickColor.new("Lime green")
BarrierField.Shape = "Ball"
BarrierField.Material = "Neon"
BarrierField.Anchored = true
BarrierField.CanCollide = true
BarrierField.Transparency = 0.5
BarrierField.Size = Vector3.new(32,32,32)
BarrierField.CFrame = char.HumanoidRootPart.CFrame
BarrierField.Locked = true
BarrierField.Parent = char
wait(7)
BarrierField:Destroy()
end
wait(5)
Enabled = true
end)

4 comments
KeyDown is decaperated, use InputBegan from UserInputService
you are setting properties of parts from a local script, that doesn't work in an actual game
it does work
i need answers