Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I make my Element from not being spam-able in FE due to not one massive script?

Asked by 5 years ago

For example,

UserInput.InputBegan:connect(function(input,gpe)    
if not gpe and input.KeyCode == Enum.KeyCode.F and enabled == false then
enabled = true

the

enabled = true

allows me to make it so the element cannon't be spammed as I can change it to false when the element has fired from the player.

However, in FE since the scripts are not together but client-server script how would I make this work as I used parts of UIS to make this work, but because the script isn't one big script, how would i make the non spam-able be able to work?

I've already tried if statements in the server script but it doesn't seem to change anything.

FE

client

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local RemoteEvent = game.Workspace.Fired
local UserInput = game:GetService("UserInputService")

local Debounce = false
local Player = script.Parent.Parent
local stopDelay = 1
local enabled = false




UserInput.InputBegan:connect(function(input,gpe)    
if not gpe and input.KeyCode == Enum.KeyCode.F then
if Debounce == true then return end     
RemoteEvent:FireServer(Debounce) 
wait(stopDelay)


end 
end)

FE Server

local Player = script.Parent.Parent
game.Workspace.Fired.OnServerEvent:Connect(function(Player, Debounce)
--local Player = game.Players.LocalPlayer

--local AlreadyTouched = false
local Character = Player.Character or Player.CharacterAdded:wait() 
Debounce = true

game:GetService("Chat"):Chat(Player.Character.Head, "Fire: Golden Blaze")
--local enabled = true  
--local Player = script.Parent.Parent
local x = Instance.new("Part")
x.BrickColor = BrickColor.new("Gold")
x.Size = Vector3.new(5, 5, 5)
x.TopSurface = "Smooth"
x.BottomSurface = "Smooth"
x.Shape = "Ball"
x.Name = Player.Name
x.CanCollide = false
x.Transparency = 0
x.Material = "Neon"
local fd = script.Damage:clone()
fd.Parent = x
y = Instance.new("BodyVelocity")
y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
y.velocity = Player.Character.HumanoidRootPart.CFrame.lookVector*80
x.Parent = workspace
y.Parent = x
local f = Instance.new("Fire", x)
f.Color = Color3.new (255,55,0)
f.Size = 2
f.Heat = 50
x.CFrame = Player.Character.HumanoidRootPart.CFrame*CFrame.new(0, 0, -12)
fd.Disabled = false
game.Debris:AddItem(x, 6)
--game.Soundscape.blaster:Play()
wait(0.25)

wait(2)
Debounce = false
--enabled = false
print "ended"


end)

1 answer

Log in to vote
0
Answered by
CPF2 406 Moderation Voter
5 years ago
Edited 5 years ago

For this, you should have separate debounces on the server and client, to prevent exploiters from firing the remote all they want, here is an example.

CLIENT:

local UserInputService = game:GetService("UserInputService")
local Remote = game.Workspace.Fired
local debounce = false

local function onInputBegan(input,gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard and not gameProcessed and input == Enum.KeyCode.F and not debounce then

    debounce = true

    Remote:FireServer()

    delay(2,function()
        debounce = false
    end)

    end
end

UserInputService.InputBegan:Connect(onInputBegan)

SERVER:

local Players = game:GetService("Players")
local Remote = game.Workspace.Fired


local function onPlayerAdded(player)

    local debounceValue = Instance.new('BoolValue')
    debounceValue.Value = false
    debounceValue.Name = Remote.Name.. 'Debounce'
    debounceValue.Parent = player

end

local function onRemoteFired(player)

    if player:FindFirstChild(Remote.Name.. 'Debounce' then

        local debounceValue = player:FindFirstChild(Remote.Name.. 'Debounce').Value

        if debounceValue.Value == false then

            debounceValue.Value = true

            print('Remote Success')

            delay(2,function()
                debounceValue.Value = false
            end)

        else

            print('Remote Error, Debounce is Active')

        end

    else

        print('Remote Error, Debounce Value Not Found')

    end

end

Players.PlayerAdded:Connect(onPlayerAdded)
Remote.OnServerEvent:Connect(onRemoteFired)
0
On line seven the second argument of Instance.new is deprecated. Parent the BoolValue after setting all its properties. User#21908 42 — 5y
0
Good to know, sucks that it is deprecated though. CPF2 406 — 5y
Ad

Answer this question