Hi, i’m trying to make it so that if the player has the stringvalue, NormalPlayerSize, they will shrink if they touched the part. Here is my code
local Touch
local Player = game.Players:GetPlayers()
local NormalPlayerSizeTag = Player:FindFirstChild("NormalPlayerSize")
Touch = script.Parent.Touched:Connect(function(hit)
if Player:FindFirstChild("NormalPlayerSize") and not Player:FindFirstChild("Piggy") then
local Humanoid = hit.Parent:FindFirstChild("Humanoid")
if Humanoid then
local HD = Humanoid:GetAppliedDescription()
HD.HeadScale = HD.HeadScale * .4
HD.DepthScale = HD.DepthScale * .4
HD.WidthScale = HD.WidthScale * .4
HD.HeightScale = HD.HeightScale * .4
Humanoid:ApplyDescription(HD)
end
NormalPlayerSizeTag:Destroy()
end
end)
GetPlayers returns a table of all the players inside game.Players service, you can’t use it like that.
Instead what you can do is grab the player from the hit so it’ll be :
local Players = game:GetService("Players")
script.Parent.Touched:Connect(function(hit)
local Player = hit.Parent and hit.Parent:FindFirstChild("Humanoid")
Player = Player and Players:GetPlayerFromCharacter(Player.Parent) -- Player would be Humanoid and Player.Parent would be their character
if not Player then return end
-- your code based on Player
end)
local Player = game:GetService("Players")
local NormalPlayerSizeTag = Player:FindFirstChild("NormalPlayerSize")
script.Parent.Touched:Connect(function(hit)
-- if Player:FindFirstChild("NormalPlayerSize") and not Player:FindFirstChild("Piggy") then
local Player = hit.Parent and hit.Parent:FindFirstChild("Humanoid")
Player = Player and Player:GetPlayerFromCharacter(Player.Parent) -- Player would be Humanoid and Player.Parent would be their character
if not Player then return end
Player.HeadScale = Player.HeadScale * .4
Player.DepthScale = Player.DepthScale * .4
Player.WidthScale = Player.WidthScale * .4
Player.HeightScale = Player.HeightScale * .4
NormalPlayerSizeTag:Destroy()
--end
end)
It appears you’re indexing all the players (an array) instead of just a singular player.
local Touch
Touch = script.Parent.Touched:Connect(function(hit)
local Player = game.Players:GetPlayerFromCharacter(hit.Parent)
if (Player) then
local NPS = Player:FindFirstChild("NormalPlayerSize")
local P = Player:FindFirstChild("Piggy")
if (NPS) and (not P) then
local Humanoid = Player.Character:FindFirstChild("Humanoid")
if Humanoid then
local HD = Humanoid:GetAppliedDescription()
HD.HeadScale = HD.HeadScale * .4
HD.DepthScale = HD.DepthScale * .4
HD.WidthScale = HD.WidthScale * .4
HD.HeightScale = HD.HeightScale * .4
Humanoid:ApplyDescription(HD)
end
NPS:Destroy()
end
end
end)