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

How do I make "x" do 20 damage to everybody who touches it apart from who presses the key?

local player = game.Players.LocalPlayer

local mouse = player:GetMouse()
	mouse.KeyDown:connect(function(key)

	if key == "q" then
		
		
		local po = game.Players.LocalPlayer

local Discharge = Instance.new("Animation")
	Discharge.AnimationId = "http://www.roblox.com/Asset?ID=218063418"
local animTrack = po.Character.Humanoid:LoadAnimation(Discharge)
		animTrack:Play()
	
		wait(1)
		
		Player = script.Parent.Parent


		game:GetService("Chat"):Chat(Player.Character.Head, "Discharge!")-- Change this if you want to say something else
	
	
		x =	Instance.new("Part")
		
		
		x.Reflectance = 0.5
		x.Size = Vector3.new(20, 20, 20)
		x.BrickColor = BrickColor.new("Bright yellow")
		x.TopSurface = "Smooth"
		x.BottomSurface = "Smooth"
		x.Shape = "Ball"
		x.Name = Player.Name
		x.Anchored = true
		x.CanCollide = false 
		x.Transparency = 0.6 
		y = Instance.new("BodyVelocity")
		y.maxForce = Vector3.new(math.huge, math.huge, math.huge)
		y.velocity = Player.Character.Torso.CFrame.lookVector*80
		x.Parent = Workspace
		y.Parent = x
		x.CFrame = Player.Character.Torso.CFrame*CFrame.new(0, 0, 0)
		
		w = Instance.new('Weld')

w.Part0 = x
w.Part1 = Player.Character.Torso
w.Parent = x




	
	game.Debris:AddItem(x, 4)
	
	
	
	
	end
		end)

I edited the whole script.

3 comments

0

I wont be able to answer anything I missed out for a couple of hours sorry.

0

Is this the full script? Because it appears there is code missing.

0

No I can edit it to the full script but ot right now.

2 answers

✓ Accepted answer

@Sciptr, There's no point in using a table (seeing as there will only ever be one player), and you can't access the player's mouse from a server-side script (so this has to be done from a client-side script, aka a LocalScript).

@Neo, This is a rather simple thing to accomplish. All you require is an if statement and the Touched event. See below for an example section which you'd add to your code after creating the sphere.

x.Touched:connect(function(Hit)
	local HitPlayer = game.Players:GetPlayerFromCharacter(Hit.Parent)
	if HitPlayer and HitPlayer ~= player and Hit.Parent:FindFirstChild("Humanoid") then
 		Hit.Parent.Humanoid:TakeDamage(20) 
	end
end)

In essence it's exactly the same as what Sciptr was doing, but in far less convoluted manner. All that's occurring here is that the if statement is checking that a player was hit, that the player being hit isn't the LocalPlayer and that the hit player has a Humanoid. If all of these conditions are met, the player who was hit will lose 20 health (though use of a debounce may be necessary).

1 comment

0

Thank you so much :D

safeplayers = {}
local player = game.Players.LocalPlayer

local mouse = player:GetMouse()
	mouse.KeyDown:connect(function(key)
 		 if key == "q" then
 			table.insert(safeplayers,player.Name)
		end
	end)
end)

-- replace this to point to the part you want.
local part = game.Workspace["Part"]

part.Touched:connect(plr)
	-- index the safe players?
	local issafe=false
	for i=1,#safeplayers do
		if safeplayers[i]==plr.Name then
			issafe=true
		end
	end
	-- harm the player if he is not on the list
	if issafe==false then game.Players.Workspace[plr.Name].Humanoid:TakeDamage(20) end
end)

Hopefully this gives you a better idea, I have not tested it and I recommend recoding it for a Script, not a local script.

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