I’ll make this as quick as I can, this code isn’t working when it should:
script.Parent.Touched:Connect(function(hit)
local player = hit.Parent
game.ReplicatedStorage.SpawnNewStair:FireClient(game.Players:GetPlayerFromCharacter(player))
end)
local PS = game:GetService("Players")
local part: BasePart = script.Parent
part.Touched:Connect(function(hit: BasePart)
local char = hit:FindFirstAncestorWhichIsA("Model")
local player = char and PS:GetPlayerFromCharacter(char)
if player then
game.ReplicatedStorage.SpawnNewStair:FireClient(player)
end
end)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") or hit.Parent.Parent:FindFirstChild("Humanoid") then
local player = hit.Parent
game.ReplicatedStorage.SpawnNewStair:FireClient(game.Players:GetPlayerFromCharacter(player))
end
end)
if hit.Parent:FindFirstChild("Humanoid") then
game.ReplicatedStorage.SpawnNewStair:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent))
else
game.ReplicatedStorage.SpawnNewStair:FireClient(game.Players:GetPlayerFromCharacter(hit.Parent.Parent))
end
script.Parent.Touched:Connect(function(hit)
local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if typeof(player) == 'Instance' then
game:GetService("ReplicatedStorage").SpawnNewStair:FireClient(player)
end
end)
to check for a model ancestor instead of checking if the touch part’s parent is a character or it’s parent’s parent is a character (and so on and so forth).