So here’s the deal. I have a tattoo parlor and with a wall of tattoos that are numbered and I have 2 tattoo chairs. You need to sit in one of the chairs and say the tattoo you want and to part you want it to apply the decal on. I would say something like “3 left arm”. I have two scripts to handle this and it almost works but I’m not sure what is causing this hickup. It works if I don’t use spaces in the word, if I say “3 leftleg” it works but if I say “3 left leg” it won’t apply the decal. IF anyone can explain what’s wrong I would appreciate it. Here are the scripts. The first one is a local script in starterplayerscripts. and the second is a script in the serverscriptservice.
local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild(“PlayerGui”)
local function onPlayerChat(message)
– Split the message into parts: the first part is the tattoo number, the rest is the body part
local parts = message:split(" ", 2) – Only split at the first space
-- Ensure there are at least two parts (tattoo number and body part)
if #parts < 2 then return end
-- Get the tattoo number (first part)
local tattooNumber = tonumber(parts[1])
-- Get the body part (second part, which includes spaces if any)
local bodyPart = parts[2]
-- Print for debugging
print("Chat Message:", message)
print("Tattoo Number:", tattooNumber)
print("Body Part before normalization:", bodyPart)
-- Check if tattooNumber and bodyPart are valid
if tattooNumber and bodyPart then
-- Normalize the body part: remove spaces and convert to lowercase
local normalizedBodyPart = bodyPart:lower():gsub("%s+", "") -- Remove spaces and convert to lowercase
-- Print for debugging
print("Body Part after normalization:", normalizedBodyPart)
-- Call a remote event to apply the tattoo
game.ReplicatedStorage.TattooRemote:FireServer(tattooNumber, normalizedBodyPart)
end
end
– Listen for the player’s chat messages
player.Chatted:Connect(onPlayerChat)
Here is the second script.
local remote = Instance.new(“RemoteEvent”)
remote.Name = “TattooRemote”
remote.Parent = game.ReplicatedStorage
local tattooDecals = {
[1] = “6343535380”, – ID’s for the decals
[2] = “4920916286”,
[3] = “4908045547”,
[4] = “4920916582”,
[5] = “51298728”,
[6] = “8361012618”,
[7] = “383151290”,
[8] = “63548458”,
[9] = “37248143”,
[10] = “101758633”,
[11] = “94201575”,
[12] = “1451752964”,
}
local function isPlayerInTattooSeat(player)
local character = player.Character
if not character then return false end
local humanoid = character:FindFirstChildOfClass("Humanoid")
if not humanoid then return false end
local seated = humanoid.SeatPart
return seated and (seated.Name == "tatseat1" or seated.Name == "tatseat2")
end
local function applyTattoo(player, tattooNumber, bodyPart)
if not isPlayerInTattooSeat(player) then
player:SendNotification({
Title = “Error”,
Text = “You must be seated in a tattoo chair to get a tattoo.”,
Duration = 5,
})
return
end
local character = player.Character
if not character then return end
local tattooID = tattooDecals[tattooNumber]
if tattooID then
local part
local humanoid = character:FindFirstChildOfClass("Humanoid")
-- Print for debugging
print("Body part received by server:", bodyPart)
-- Normalize the body part (remove spaces and lowercase everything)
local normalizedBodyPart = bodyPart:lower():gsub("%s+", "")
-- Print for debugging
print("Normalized Body Part on Server:", normalizedBodyPart)
-- Check if the avatar is R6 or R15
if humanoid.RigType == Enum.HumanoidRigType.R6 then
if normalizedBodyPart == "face" then
part = character:FindFirstChild("Head")
elseif normalizedBodyPart == "chest" then
part = character:FindFirstChild("Torso")
elseif normalizedBodyPart == "leftarm" then
part = character:FindFirstChild("Left Arm")
elseif normalizedBodyPart == "rightarm" then
part = character:FindFirstChild("Right Arm")
elseif normalizedBodyPart == "leftleg" then
part = character:FindFirstChild("Left Leg")
elseif normalizedBodyPart == "rightleg" then
part = character:FindFirstChild("Right Leg")
end
elseif humanoid.RigType == Enum.HumanoidRigType.R15 then
if normalizedBodyPart == "face" then
part = character:FindFirstChild("Head")
elseif normalizedBodyPart == "chest" then
part = character:FindFirstChild("Upper Torso")
elseif normalizedBodyPart == "leftarm" then
part = character:FindFirstChild("LeftLowerArm")
elseif normalizedBodyPart == "rightarm" then
part = character:FindFirstChild("RightLowerArm")
elseif normalizedBodyPart == "leftleg" then
part = character:FindFirstChild("LeftLowerLeg")
elseif normalizedBodyPart == "rightleg" then
part = character:FindFirstChild("RightLowerLeg")
elseif normalizedBodyPart == "neck" then
part = character:FindFirstChild("Neck") -- Optional for R15
end
end
-- Debugging: Print if part is found or not
if part then
print("Found part:", part.Name)
local decal = Instance.new("Decal")
decal.Texture = "rbxassetid://" .. tattooID
decal.Parent = part
-- Set properties for the decal here
decal.Face = Enum.NormalId.Front
decal.Transparency = 0
-- Play the tattoo gun sound
local seatPart = player.Character.Humanoid.SeatPart
if seatPart and seatPart:FindFirstChild("Sound") then
local sound = seatPart.Sound
sound:Play()
print("Sound played.")
end
else
-- Debugging: Print if part could not be found
print("Could not find part for body part:", bodyPart)
end
end
end
– Listen for remote events
remote.OnServerEvent:Connect(function(player, tattooNumber, bodyPart)
– Ensure bodyPart and tattooNumber are received correctly
if type(tattooNumber) == “number” and type(bodyPart) == “string” then
– Debugging: Print tattoo number and body part received
print(“Tattoo Number:”, tattooNumber)
print(“Received Body Part:”, bodyPart)
-- Normalize body part (remove spaces and lowercase it)
local normalizedBodyPart = bodyPart:lower():gsub("%s+", "")
applyTattoo(player, tattooNumber, normalizedBodyPart)
end
end)