How would I find who is using a tool? For example. I want to tell if someone’s team is the same as the person using the tool’s team.
The player using a Tool is the Parent of the Tool. When a player equips a Tool, it is placed into their Character.
-- ServerScript in Tool
script.Parent.Equipped:Connect(function()
local User = game.Players:GetPlayerFromCharacter(script.Parent.Parent) -- Parent of the Tool
print(`The user of this tool is {User}!`)
end)
When the player triggers the Tool (reference this with the Activated event), you can get the using player by using the GetPlayerFromCharacter method of Players to get the actual Player.
Anyway to see when a player gets hit by the tool if they are on the same team if they arent then they die?
Check if the parent of the Part that was hit is a Character of a Player, again by using GetPlayerFromCharacter. Then, compare the Player.Team property of the victim and the attacker; if they are not the same, damage the victim.
so how would i make this work?
local tr = true
local Player = game.Players.LocalPlayer
local Tool = script.Parent
local Script = script
local Animation = Tool:WaitForChild("HitAnim1")
local HoldAnim = Tool:WaitForChild("HoldAnim")
local Character = Player.Character or Player.CharacterAdded:Wait()
local Hit1 = Character:FindFirstChildOfClass("Humanoid"):LoadAnimation(Animation)
local Hold = Character:FindFirstChildOfClass("Humanoid"):LoadAnimation(HoldAnim)
local PlayerEquiped = script.Parent.Parent.Parent
Tool.Equipped:Connect(function()
Hold:Play()
end)
Tool.Activated:Connect(function()
if tr == true then
Hit1:Play()
script.Parent.Slash:Play()
tr = false
wait(0.5)
tr = true
end
end)
Tool.Unequipped:Connect(function()
Hold:Stop()
end)
Tool.Hitbox.Touched:Connect(function(hit) --here is the part im doing.
if hit == Character then
if hit.Parent.Team == Tool.Parent.Parent.Team then
end
end
end)
I just wanna ask here, are you trying to create a tool where once it comes in contact with a player (that is not on the same team) kills them, otherwise it does nothing?
yes im maing a game sorta like big paintball but with bats
and this is a local script, correct?*
yes char char char char
Okay so basically hit is gonna be the part that came in contact with it, you can use:
local tr = true
local Players = game:GetService(“Players”)
local Player = Players.LocalPlayer
local Tool = script.Parent
local Animation = Tool:WaitForChild(“HitAnim1”)
local HoldAnim = Tool:WaitForChild(“HoldAnim”)
local Character = Player.Character or Player.CharacterAdded:Wait()
local Hit1 = Character:FindFirstChildOfClass(“Humanoid”):LoadAnimation(Animation)
local Hold = Character:FindFirstChildOfClass(“Humanoid”):LoadAnimation(HoldAnim)
local PlayerEquiped = script.Parent.Parent.Parent
Tool.HitBox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild(“Humanoid”) then
– It’s a player
local otherPlayer = Players:GetPlayerFromCharacter(hit.Parent)
if otherPlayer then
if otherPlayer.Team ~= Player.Team then -- Not on the same team
-- Do some stuff here
end
end
end
end)
I will try to do it real quick.
It may or may not work. Let me know!
i cant enter in the script rn because it shows this and i cant see my script because the big bar going up doesnt have a delete button should i report this to roblox support?
Woah. I never seen that before, but if you can’t work around it 100% report it to Roblox.
I do also think that’s your explorer?
no its saying the last time i was editing with someone it didnt save then so its showing the scripts that werent saved yet i cannot see them because its at the top.
nvm i fixed it. dont stress about it
didnt work sadly
can you look over the script?
Did you get any errors in the console or anything?
I just tested this, and it works!
Tool.HitBox.Touched:Connect(function(hit)
print("touched", hit)
if hit.Parent:FindFirstChild("Humanoid") then
-- It's a player
local otherPlayer = Players:GetPlayerFromCharacter(hit.Parent)
if otherPlayer then
if otherPlayer.Team.Name ~= Player.Team.Name then
print(otherPlayer.Name, "is not on the same team.")
end
end
end
end)
