Hey there! I’m making a Model/Runway game and I’m not quite sure where to start. There’s a lot to script and I really aren’t that good at scripting. I’m fine with the building and all of that, but I just need help with scripting it. I want to make a staff morph where if you touch the part to equip the morph, you equip the heels and gloves. I’ve tried videos but all they “teach” me is how to weld your feet to the heels or weld your hands to the gloves with F3X, and I already know all of that. I have tried to search the DevForum but I really can’t find what I’m looking for. If you understand and have the time, please try to help by trying to explain what to do in the comments. Thanks! ![]()
You want to use the BasePart.Touched event on a part in your map to connect a function that changes the desired body part on the player using a MeshID or adds an accessory to the character.
To use this you would do something that would look like this
--Define your variables
local PlayerService = game:GetService("Players")--[[
This is a service which we'll use to get the character.
]]--
local Part = script.Parent
--[[
Events return certain values like parts and numbers when fired called `Parameters`.
You can get the returned parameters through the function call after the event has been fired.
]]--
--Define your function to use when the event is fired.
local function OnTouch(PartThatTouched)--Parameter of the function
local Player = PlayerService:GetPlayerFromCharacter(PartThatTouched.Parent)--Use PlayerService to find the Player from the part that touched the morph part if it's a part inside the character.
local Character = nil
if Player then--[[
Check if the player was found
then redefine the character variable to the Character parameter that was returned from the GetPlayerFromCharacter function of PlayerService if it was
]]--
Character = Player.Character
end
if Character then
local Humanoid = Character:FindFirstChildWhichIsA("Humanoid")--[[
Get the Humanoid by using a function on the Character Model called
FindFirstChildWhichIs which searches through the model's children to get the first child with a ClassName of Humanoid
Or find the first Humanoid in the model.
]]--
print("Do something with the Character Model here.")
end
end
Part.Touched:Connect(OnTouch)--[[
This is an event object and how you create one.
You can also make them a variable by typing
local EventName =
before creating an event object.
So that you can use a function on the event by doing
Event:Disconnect()
if you need to.
]]
You can use the Roblox Developer API to find, properties of instances, functions of instances, events of instances, and parameters returned from these events.
The Roblox Developer Hub in general is a good place to find tutorials.
Here’s articles on:
-Variables
-Functions
-Events and How To Handle them
And a gameplay article on Detecting Collisions
I know this is a lot so if you have any questions don’t be afraid to ask.
EDIT: Humanoid was not defined and the script would error if you tried to run it. It should work now let me know if it doesn’t.