To create a Roblox script that prints the name of the instance a player is touching with their feet, you can use a LocalScript to detect when the player's humanoid's foot touches another part.
Here's an example of how you might set up such a script. This script should be placed inside a LocalScript under the StarterCharacterScripts, which ensures it runs for each player's character:
lua
-- LocalScript under StarterCharacterScripts or StarterPlayerScripts
local function onTouched(part)
-- Check if the part is not the player's character
local character = script.Parent
if part:IsDescendantOf(character) then return end
-- Print the name of the part
print("Touching: " .. part.Name)
end
local function waitForHumanoid(character)
while not character:FindFirstChildOfClass("Humanoid") do
character.ChildAdded:wait()
end
end
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
waitForHumanoid(character)
-- Find the humanoid's foot parts (assuming the feet are named "LeftFoot" and "RightFoot")
local leftFoot = character:WaitForChild("LeftFoot")
local rightFoot = character:WaitForChild("RightFoot")
-- Connect the Touched event to the onTouched function for both feet
leftFoot.Touched:Connect(onTouched)
rightFoot.Touched:Connect(onTouched)
Please note a couple of important points about this script:
This script assumes that the player's character has parts named "LeftFoot" and "RightFoot." You may need to adjust the script to match the actual names of the foot parts in your character model.
The Touched event can fire multiple times for a single touch, due to the physics engine's behavior. If you need to only print the name once per touch, you will need to implement additional logic to debounce the event.
In some cases, you may need to filter out certain parts or only allow specific instances. You can adjust the onTouched function to include such logic.
This script uses LocalScript because touch detection usually involves client-side interaction. LocalScripts run on the client (the player's device), not on the server.
Always be aware of the security implications of client-side scripts. Since clients can manipulate LocalScripts, any important game logic should be verified on the server side.
The script uses ChildAdded:wait() and CharacterAdded:wait() to ensure that it doesn't attempt to access parts of the character before they exist.
Insert this LocalScript into StarterCharacterScripts within StarterPlayer to ensure that it is cloned into each player's character model when they spawn.