im trying to create an ability in my roblox game that im making in roblox studio the latest version. im trying to create a summoning script for my necromancer class what i want to happen is when i press e i want to summon a model of my choosing i also want to follow me at a distance minimum 10 meters and stay around me constantly they can move around but they need to stay around and guard me how do i achieve this
Creating a summoning ability for a Necromancer class in Rob Studio involves several steps, including scripting the summoning action, creating the AI for the summoned entity, and managing its behavior around the player. Below is a high-level guide on how you could implement the summoning ability.
First, ensure you have a model that you want to use for summoned entity. Make sure it's properly set up for animations if needed.
Next, you'll need two main scripts: one LocalScript to detect when the player presses 'E' and a Script for the summoned's behavior.
Here's a basic example using a LocalScript:
local UserInputService = game:GetService("UserInputService") function onKeyPress(input) if input.KeyCode == Enum.KeyCode.E then -- Call a RemoteEvent to tell server to summon the entity game.ReplicatedStorage.SummonEvent:FireServer() end end UserInputService.InputBegan:Connect(onKeyPress``` Note: For this to work, you must have `RemoteEvent` called `SummonEvent` in `ReplicatedStorage`. This event will communicate from the client (the local player) to the server. 2. **RemoteEvent and Summon (Script)**: On the server side, you listen for this event and handle theing. Place a Script within ServerScriptService. ```lualocal SummonEvent = game.ReplicatedStorage.SummonEvent function summonNromancerMinion(player) -- The minion model local minionModel =.ServerStorage.MinionModel:Clone() minionModel.HumanoidRootPartFrame = player.Character.HumanoidRootPart.CFrame + Vector3.new(0, 0 -10) -- Spawn 10 meters behind player minionModel.Parent = game.Workspace -- More AI setup code here end SummonEvent.OnServerEvent:Connect(sumNecromancerMinion)
Make sure to have the minion model in ServerStorage to clone it from there.
Here is a simplified version of the follower script that you might add inside your minion model:
local minion = script.Parent local target -- The player's to follow local followDistance = 10 -- The distance to from the target function onSummon(player) target = player.Character while target and minion:FindFirstChild("HumanoidRootPart") do local targetPosition = target.HumanoidRootPart.Position local myPosition = minion.HumanoidRootPart.Position local distance = (targetPosition - myPosition).magnitude if distance > followDistance then -- Move towards player minion.Humanoid:MoveTo(targetPosition - (Position - myPosition).unit * followDistance) end wait(0.1) -- Update follower's position every 0.1 seconds end end while not minion:FindFirstChild("HumanoidRootPart") do wait() end (1) -- Wait a second for the player to be set properly from summonNecromancerMinion function -- Start onSummon(minion.Player.Value) -- Assuming you stored the player in the minion model as a value
Please that you would typically place pathfinding logic using the RobloxfindingService for more complex minion movement like avoiding obstacles etc. Also, consider the minion's lifetime and whether it should be destroyed after a period of time or after certain conditions.
You will need to customize these scripts to better fit your game's logic and the details of the summoned entities. This involves proper error-checking and making sure your scripts communicate correctly, that your summoned entities behave as expected.
Remember that all these scripts need to be properly secured and optimized for your game to maintain performance and security. Lastly, testing AI behavior thoroughly is essential to ensure a good player experience.
i renamed the model to Skeleton make sure it updated in our scripts also this is what the skeleton has in its hierarchy i took a picture of it also i received this error
CFrame is not a valid member of Humanoid "Skeleton.HumanoidRootPart" - Server - Script:6 02:43:55.852 Stack Begin - Studio 02:43:55.852 Script 'ServerScriptService.Script', Line 6 - function summonNecromancerMinion - Studio - Script:6 02:43:55.852 Stack End - Studio
It seems like there was a typo in the script I provided earlier. TheHumanoidRootPartof the
Skeletonmodel doesn have a property called
CFrame; instead, the
CFrameproperty exists on the
oidRootPart` itself.
Let's go through the steps again, this time correcting the mistake and replacing the placeholder MinionModel
with Skeleton
in the scripts.'ll provide snippets that you should update in the previously given codeFirst, the corrected part to clone the Skeleton
and place it at the appropriate distance from the player:
function summonNecromancerion(player) -- The skeleton model local skeleton = game.ServerStorage.Skeleton:Clone() skeleton.HumanRootPart.CFrame = player.Character.HumanoidRootPartFrame * CFrame.new(0, 0, -10) -- Update here skeleton.Parent = game.Workspace -- More AI setup code here, e.g., calling the function to make it end
Update the code block where the Skeleton model is set up to follow the player:
local skeleton = script.Parent local target The player's character to follow local followDistance = 10 -- The distance to from the target function onSummon(player) target =.Character while target and skeleton:FindFirstChild("HumanoidRootPart") do -- Your logic to make the skeleton follow the player end wait(0.1) -- Update follower's position every 0.1 seconds end -- The you need to replace with appropriate code that runs when the skeleton summoned. -- This should be called after the skeleton is cloned in summonNecromancerMinion function. ``Also, it's good practice to pass the player (or their character) to the following logic, so the `Skeleton` knows who to follow. If you're storing a reference to the player within the `Skeleton` model (e.g., setting a `Player` value
02:57:44.351 HumanoidRootPart is not a valid member of Model "Skeleton" - Server - Script:6 02:57:44.352 Stack Begin - Studio 02:57:44.352 Script 'ServerScriptService.Script', Line 6 - function summonNecromancerMinion - Studio - Script:6 02:57:44.352 Stack End
The error message indicates that there might be a problem with how you are trying to access the HumanoidRootPart
within the Skeleton
model. It is possible that when you took a picture of the hierarchy, the HumanoidRootPart
was not present, wasn't properly named, or the model structure was different than expected.
Make sure that your Skeleton
model indeed has a part named HumanoidRootPart
and that it is a direct child of the model. If the part exists but is named differently, you'll have to adjust your script to match the exact name in the hierarchy.
Here is an example of how to handle the situation when your skeleton model does not have a part called HumanoidRootPart
. You have to use another part within the model to position the skeleton relative to the player. This code assumes you have a primary part within the Skeleton
model that can be used for positioning.
First, review your Skeleton
hierarchy and identify the primary part you can use for positioning. Let's say it is called SkeletonBasePart
. You would then update the summon function like this:
function summonNecromancerMinion(player) local skeleton = game.ServerStorage.Skeleton:Clone() -- Ensure this is a Model local skeletonPrimaryPart = skeleton:FindFirstChild("SkeletonBasePart") -- Replace with your actual primary part's name if skeletonPrimaryPart and player.Character and player.Character:FindFirstChild("HumanoidRootPart") then -- Position the skeleton 10 meters behind the player skeletonPrimaryPart.CFrame = player.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -10) skeleton.Parent = game.Workspace -- More AI setup code here else -- Handle the situation where the expected parts are not found print("Could not find main parts in the Skeleton model or player's character.") end end
Make sure to replace "SkeletonBasePart"
with the actual name of the primary part from your Skeleton
model.
If your Skeleton
model is designed to work with Roblox's default character system, it should have a HumanoidRootPart
unless there has been a mistake in setting it up. The structure should be similar to a standard Roblox character model for compatibility.
If the problem persists, double-check your Skeleton
model setup in Roblox Studio:
Skeleton
model.HumanoidRootPart
.HumanoidRootPart
, then anchor it and set it as the primary part if it's not already set like that.Remember that every aspect of your code that references the HumanoidRootPart
must match the actual structure and naming conventions you're using in your model. If any discrepancies exist, these will cause errors like the one you're encountering.