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

make new instance from tool not damage player wielding it?

Asked by
pwgth 11
3 years ago

ok, so I have a tool that makes an instance spawn. the new instance has a code which then damages all players who touch it. but that's the problem, since it spawns at the position of the player... I think you get the point.

01local tool = script.Parent
02local mouse
03local debounce = false
04local dmg = --set damage here
05 
06tool.Equipped:Connect(function(m)
07    mouse = m
08end)
09 
10tool.Activated:Connect(function()
11    if mouse then
12        local Part = Instance.new("Part",workspace)
13        Part.Position = script.parent.Handle.Position
14        Part.Material = Enum.Material.Neon
15        Part.Size = Vector3.new(0.5,0.5,0.5)
View all 29 lines...

I know I've been asking a lot of questions here but I just cant find the answer... it would also be appreciated if you could put the link to teach me about this kind of stuff. like in here: https://developer.roblox.com

1 answer

Log in to vote
1
Answered by 3 years ago

So I fixed it:

01local tool = script.Parent
02local mouse
03local debounce = false
04local dmg = --set damage here
05local player
06 
07tool.Equipped:Connect(function(m)
08    mouse = m
09    player = game.Players:GetPlayerFromCharacter(tool.Parent)
10end)
11 
12tool.Activated:Connect(function()
13    if mouse then
14        local Part = Instance.new("Part",workspace)
15        Part.Position = script.parent.Handle.Position
View all 33 lines...

What I did here, was getting the player using :GetPlayerFromCharacter on tool.Parent. Whenever the Instance is hit, it will check if the hit name is not equal to the player name.

I wasn't able to test it right now, but I hope it helped! You can always put down a comment if it didn't work.

0
After making some of my own changes, It worked! at first it didn't but after a couple rounds of trial and error it worked, thanks bud! pwgth 11 — 3y
0
well, kind of... while testing it didn't hurt the other player but well find a way. pwgth 11 — 3y
Ad

Answer this question