in what way is it not working? are there any errors in the console? if its simply not doing anything then you need to put print statements before/after lines of code to see if they are running
Your code is a bit messy, but I think I understand what you’re trying to do. Ensure that this is a LocalScript, so that we can access Players.LocalPlayer and use UserInputService. Good luck!
local KeyBinding = game:GetService("UserInputService")
local playerCharacter = game.Players.LocalPlayer.Character
local humanoid = playerCharacter:FindFirstChildOfClass("Humanoid")
KeyBinding.InputBegan:Connect(function(input, processed)
if processed then return end
if input.KeyCode == Enum.KeyCode.E then
script.Parent.ChangeNPC:Fire()
end
end)
local SelectedNPC = script.Parent.Selected
script.Parent.ChangeNPC.Event:Connect(function()
humanoid:LoadAnimation(script.Parent.Animations.Change):Play()
end)
script.Parent.Activated:Connect(function()
humanoid:LoadAnimation(script.Parent.Animations.Use):Play()
end)
humanoid:LoadAnimation(script.Parent.Animations.Change).GetMarkerReachedSignal("ChangeEvent"):Connect(function()
local NPCStorage = game.ServerStorage.NpcSpellStorage:GetChildren()
local ChosenNPC = NPCStorage[math.random(1, #NPCStorage)]
script.Parent.Part.Change:Play()
SelectedNPC.Value = ChosenNPC
script.Parent.Part.Color = SelectedNPC.Value.Torso.Color
script.Parent.Part.Face.Texture = SelectedNPC.Value.Head:FindFirstChildOfClass("Decal").Texture
end)
humanoid:LoadAnimation(script.Parent.Animations.Use).GetMarkerReachedSignal("CloneEvent"):Connect(function()
local Part = script.Parent.Part
if math.random(1, 500) == 1 then
script.Parent.Part["Clone (Rare)"]:Play()
else
script.Parent.Part.Clone:Play()
end
local Explode = Instance.new("Explosion")
Explode.BlastPressure = 0
Explode.BlastRadius = 0
Explode.Position = Vector3.zero() -- Please set the explosion's position
Explode.Parent = workspace
local Clone = SelectedNPC.Value:Clone()
Clone.Parent = workspace
Clone:SetPrimaryPartCFrame(Part.CFrame) -- Set the position of the cloned NPC
end)