Could anyone aid me as to why this simple script does not work. It should work accordingly but does not…
Basically, in this script when a player touches a part they decrease in size.
Below is the image of the output and the script. The output keeps saying that BodyScale as well as all the other members of the humanoid are not valid… Why?
The error suggests that BodyScale does not exist within the Humanoid. Try this instead:
script.Parent.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
for _, child in pairs(player.Character.Humanoid:GetChildren()) do
if child:IsA("NumberValue") then
child.Value = 0.5
end
end
end
end)
You could reference a debounce (Or a cooldown) so that the Sound can play in its entirely before setting it back to false
local Button = script.Parent
local Sound = Button.SoundToPlay
local DB = false
Button.Touched:Connect(function(Hit)
local Humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if Humanoid and not DB then
--Set your Humanoid Scales here
DB = true
Sound:Play()
Sound.Ended:Wait()
DB = false
end
end)
You didn’t reference a debounce in the script, so the sound would result in it playing over & over again
local Button = script.Parent
local Sound = workspace.Teleport
local DB = false
Button.Touched:Connect(function(Hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid and not DB then
humanoid.HeadScale.Value = 0.5
humanoid.BodyWidthScale.Value = 0.5
humanoid.BodyHeightScale.Value = 0.5
humanoid.BodyDepthScale.Value = 0.5
DB = true
Sound:Play()
Sound.Ended:Wait()
DB = false
end
end)
Either that or it’s something else having to do with your Sound object