Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to make it so my attack generates once?

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

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()

4 comments

0

I suggest that you learn how to use for loops as they will shorten the amount of code you will need to write.

0

While I do know how to use loops, I have a technique to make it smoother, which requires longer code.

0

The code you have written now wont make it any smoother than using a for loop pal

0

I can lin kyou the game.

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.

1 comment

0

It didn't work, by looking I could tell there are issues. Good luck learning to code!

This discussion is preserved as it was. New answers, comments, and votes are closed.