spawn(function()
while task.wait(0.5) do
for i, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
if v.Name == "Left Leg" or v.Name == "Right Leg" then
Head.Face.Texture = "http://www.roblox.com/asset/?id=910076130" -- sad face
else
Head.Face.Texture = "rbxasset://textures/face.png" -- happy face
end
end
end
end)
This script is supposed to make it so that when you stand on an enemy’s head, it becomes sad. Then when you’re no longer standing on it, it becomes happy. But what the script does right now is when you stand on the enemy’s head, it becomes sad and stays sad permanently even if you jump off. I checked and the hitbox is always in the right place, above the head, and is not touching any legs but it still won’t switch the face to happy. Can anyone help fix this?
3 Likes
rather than doing a while loop, you could try doing when Head.Touched
then get the parts within the hitbox, and when Head.TouchEnded
wait like 0.5 seconds and repeat the detection thingy
1 Like
Can you pose the new script you tried out?
1 Like
local Head = script.Parent.Head
Head.SadnessHitbox.Touched:Connect(function(v)
if v.Name == "Left Leg" or v.Name == "Right Leg" then
Head.Face.Texture = "http://www.roblox.com/asset/?id=910076130" -- sad face
else
Head.Face.Texture = "rbxasset://textures/face.png" -- happy face
end
end)
Head.SadnessHitbox.TouchEnded:Connect(function(v)
task.wait(0.5)
if v.Name == "Left Leg" or v.Name == "Right Leg" then
Head.Face.Texture = "http://www.roblox.com/asset/?id=910076130" -- sad face
else
Head.Face.Texture = "rbxasset://textures/face.png" -- happy face
end
end)
1 Like
replace the
if v.Name == "Left Leg" or v.Name == "Right Leg" then
Head.Face.Texture = "http://www.roblox.com/asset/?id=910076130" -- sad face
else
Head.Face.Texture = "rbxasset://textures/face.png" -- happy face
end
with this in both of the touch functions
for _, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
if v.Name == "Left Leg" or v.Name == "Right Leg" then
Head.Face.Texture = "http://www.roblox.com/asset/?id=910076130" -- sad face
else
Head.Face.Texture = "rbxasset://textures/face.png" -- happy face
end
end
1 Like
It still doesn’t work…
local Head = script.Parent.Head
Head.SadnessHitbox.Touched:Connect(function()
for _, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
if v.Name == "Left Leg" or v.Name == "Right Leg" then
Head.Face.Texture = "http://www.roblox.com/asset/?id=910076130" -- sad face
else
Head.Face.Texture = "rbxasset://textures/face.png" -- happy face
end
end
end)
Head.SadnessHitbox.TouchEnded:Connect(function()
task.wait(0.5)
for _, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
if v.Name == "Left Leg" or v.Name == "Right Leg" then
Head.Face.Texture = "http://www.roblox.com/asset/?id=910076130" -- sad face
else
Head.Face.Texture = "rbxasset://textures/face.png" -- happy face
end
end
end)
test what’s getting printed in the GetPartsInParts table in the TouchEnded function
Head.SadnessHitbox.TouchEnded:Connect(function()
task.wait(0.5)
for _, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
print(v.Name)
if v.Name == "Left Leg" or v.Name == "Right Leg" then
Head.Face.Texture = "http://www.roblox.com/asset/?id=910076130" -- sad face
else
Head.Face.Texture = "rbxasset://textures/face.png" -- happy face
end
end
end)
It says Left Leg, Right Leg, and HumanoidRootPart over and over
Try this, hope it helps!
local Head = script.Parent.Head
Head.SadnessHitbox.Touched:Connect(function()
for i, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
if v.Name == "Left Leg" or v.Name == "Right Leg" then
Head.face.Texture = "http://www.roblox.com/asset/?id=910076130" -- sad face
end
end
end)
while task.wait(0.5) do
if Head.face.Texture == "http://www.roblox.com/asset/?id=910076130" then
local touching = false
for i, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
if v.Name == "Left Leg" or v.Name == "Right Leg" then
touching = true
end
end
if touching == false then
Head.face.Texture = "rbxasset://textures/face.png"
end
end
end
1 Like
It works better but now if I stand still while on the head, it won’t turn sad
Well working off of ColudBoy’s script, change his while loop to this
while Head.face.Texture == "http://www.roblox.com/asset/?id=910076130" do
for _, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
if v.Name ~= "Left Leg" and not v.Name ~= "Right Leg" then
Head.face.Texture = "rbxasset://textures/face.png"
end
end
task.wait(0.5)
end
If this works give the check to him
Also highly suggest you don’t keep while loops running in the background, it can cause a lot of lag depending on what you’re doing in the loop and how many loops you have
What’s the point of the not v.Name ~= “Right Leg”
ah whoops forgot to remove those parts, just remove the not
It went back to the original problem
??
Checks what’s getting printed in the for loop
for _, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
print(v.Name) -- new text
if v.Name ~= "Left Leg" and not v.Name ~= "Right Leg" then
Head.face.Texture = "rbxasset://textures/face.png"
end
end
Try this, if it don’t work I give up
local Head = script.Parent.Head
local isTouching = false
Head.SadnessHitbox.Touched:Connect(function()
if isTouching == false then
for _, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
if v.Name == "Left Leg" or v.Name == "Right Leg" then
Head.face.Texture = "http://www.roblox.com/asset/?id=910076130" -- sad face
isTouching = true
end
end
end
end)
while isTouching == true do
local touching = false
for i, v in pairs(workspace:GetPartsInPart(Head.SadnessHitbox)) do
if v.Name == "Left Leg" or v.Name == "Right Leg" then
touching = true
end
end
if touching == false then
Head.face.Texture = "rbxasset://textures/face.png"
isTouching = false
end
end
if it does, give check to CloudBoy
Is the hitbox CanCollide off?
This text will be blurred
Now the smile won’t become sad anymore