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

How to make it so my attack generates once?

Asked by 3 years ago

So, I made an "attack" called force blast for my game, but instead of generating for 1 player, it generates for everyone. How do I fix it? Those are the scripts.

Also, if you can make it so it damages every player which touches it BUT the player which generated it, it would be great.

Video: https://streamable.com/hr84pm

Local Script.

local player = game.Players.LocalPlayer
local character = script.Parent
local remoteEvent = game.ReplicatedStorage:WaitForChild("forcebrr")
local UserInputService = game:GetService("UserInputService")
local requiredKey = Enum.KeyCode.R
local rStorage = game.ReplicatedStorage
local rep = game:GetService("ReplicatedStorage")

UserInputService.InputBegan:Connect(function(key, gameProcessed)
    if key.KeyCode == requiredKey then
        remoteEvent:FireServer()
    end
end)

Server Script.

local ReplicatedStorage =  game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("forcebrr")

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        RemoteEvent.OnServerEvent:Connect(function(Player)
            --Part creation script is in the comments, it is right here but it is too long and                   
                        will make the script harder to fix.
        end)
    end)
end)

2 answers

Log in to vote
0
Answered by 3 years ago

Part Creation Script:

local part = game.ServerStorage.ForceField:Clone()
            part.Parent = workspace
            part.Position = character.Torso.Position
            part.CanCollide = false
            part.Anchored = true
            part.Size = Vector3.new(5, 5, 5)
            part.Transparency = 0.05
            wait(0.005)
            part.Size = Vector3.new(7.5, 7.5, 7.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(10, 10, 10)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(12.5, 12.5, 12.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(15, 15, 15)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(17, 17, 17)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(19, 19, 19)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(21, 21, 21)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(23, 23, 23)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(25, 25, 25)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(26.5, 26.5, 26.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(28, 28, 28)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(29.5, 29.5, 29.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(31, 31, 31)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(32.5, 32.5, 32.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(33.5, 33.5, 33.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(34.5, 34.5, 34.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(35.5, 35.5, 35.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(36, 36, 36)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(36.5, 36.5, 36.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part:Destroy()
0
I suggest that you learn how to use for loops as they will shorten the amount of code you will need to write. DeUltimate23 142 — 3y
0
While I do know how to use loops, I have a technique to make it smoother, which requires longer code. InterDwarf 14 — 3y
0
The code you have written now wont make it any smoother than using a for loop pal DeUltimate23 142 — 3y
0
I can lin kyou the game. InterDwarf 14 — 3y
Ad
Log in to vote
0
Answered by
Oxprem 140
3 years ago

Howdy! It looks to me that your problem is originating from the server script. I am new to scripting, so this may or may not work for you.

local ReplicatedStorage =  game:GetService("ReplicatedStorage")
local RemoteEvent = ReplicatedStorage:WaitForChild("forcebrr")

local function forcebrrRemoteEvent(Player)
    local part = game.ServerStorage.ForceField:Clone()
            part.Parent = workspace
            part.Position = game.Players[Player.Name].Character.Torso.Position
            part.CanCollide = false
            part.Anchored = true
            part.Size = Vector3.new(5, 5, 5)
            part.Transparency = 0.05
            wait(0.005)
            part.Size = Vector3.new(7.5, 7.5, 7.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(10, 10, 10)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(12.5, 12.5, 12.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(15, 15, 15)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(17, 17, 17)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(19, 19, 19)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(21, 21, 21)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(23, 23, 23)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(25, 25, 25)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(26.5, 26.5, 26.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(28, 28, 28)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(29.5, 29.5, 29.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(31, 31, 31)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(32.5, 32.5, 32.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(33.5, 33.5, 33.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(34.5, 34.5, 34.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(35.5, 35.5, 35.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(36, 36, 36)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part.Size = Vector3.new(36.5, 36.5, 36.5)
            part.Transparency = part.Transparency + 0.05
            wait(0.005)
            part:Destroy()
end

RemoteEvent.OnServerEvent:Connect(forcebrrRemoteEvent)

And for the local script

local player = game.Players.LocalPlayer
local character = script.Parent
local remoteEvent = game.ReplicatedStorage:WaitForChild("forcebrr")
local UserInputService = game:GetService("UserInputService")
local requiredKey = Enum.KeyCode.R
local rStorage = game.ReplicatedStorage
local rep = game:GetService("ReplicatedStorage")

UserInputService.InputBegan:Connect(function(key, gameProcessed)
    if key.KeyCode == requiredKey then
      remoteEvent:FireServer(player)
    end
end)

I apologize if this didn't work for you, as I didn't have any time to test it.

0
It didn't work, by looking I could tell there are issues. Good luck learning to code! InterDwarf 14 — 3y

Answer this question