Heya there.
Creating an ally NPC that can be controlled using a tool. The NPC has an attribute that determines if the NPC should run towards enemies or stay near its owner. The issue is that the attribute doesn’t change.
--//Tool
local Tool = script.Parent
--//Functionality
Tool.Drakobloxxer.OnServerEvent:Connect(function(Player, Type)
local Drakobloxxer
if Type == "Summon" then
--//Sanity Checking
if Tool:GetAttribute("Summoned_Drakobloxxer") == true then
print("You already summoned one!!")
return
end
--//Spawning
Tool.GripPart.Whistle1:Play()
Tool.GripPart.Attachment.Attraction.Enabled = true
task.wait(1)
Tool.GripPart.Attachment.Attraction.Enabled = false
--//Summoning Drakobloxxer
Drakobloxxer = game:GetService("ReplicatedStorage").NPCS.Neutral.Allies.Drakobloxxer:Clone()
Drakobloxxer.Parent = game.Workspace
Drakobloxxer:PivotTo(Player.Character.PrimaryPart.CFrame * CFrame.new(-5, 0, 0))
Drakobloxxer:SetAttribute("Owner", Player.Character.Name)
Drakobloxxer.Head.Summon:Play()
--//Assigning its role
if Player.Character:HasTag("Noob") then
Drakobloxxer:AddTag("Noob")
elseif Player.Character:HasTag("Zombie") then
Drakobloxxer:AddTag("Zombie")
end
end
--
if Type == "ChangeCommand" then
Tool.GripPart.Whistle2:Play()
Tool.GripPart.Attachment.Attraction.Enabled = true
if Drakobloxxer and Drakobloxxer:GetAttribute("Attack_Mode") == true then
Drakobloxxer:SetAttribute("Attack_Mode",false)
print("Drakobloxxer defend!")
elseif Drakobloxxer and Drakobloxxer:GetAttribute("Attack_Mode") == false then
Drakobloxxer:SetAttribute("Attack_Mode",true)
print("Drakobloxxer defend!")
end
task.wait(0.3)
Tool.GripPart.Whistle2:Stop()
Tool.GripPart.Attachment.Attraction.Enabled = false
end
end)