Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Humanoid is not a valid member of Model? anyone know how to fix this?

Asked by 1 year ago
Edited 1 year ago
I'm scripting from a youtube tutorial and I'm making a tower defense game and for some reason I have a error "Humanoid is not a valid member of model Workspace.Towers.Slinger? (also the error is on line 63)

(towers is my folder where I put my towers in and slinger is the towers name) does anyone know how to fix?

https://youtu.be/wy-Z-xBYbes
that is the youtube video I used for the script and the error is on

local y = result.Position.Y + towerToSpawn.Humanoid.HipHeight + (towerToSpawn.PrimaryPart.Size.Y / 2) is the error

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

local towers = ReplicatedStorage:WaitForChild("Towers")

local camera = workspace.CurrentCamera
local gui = script.Parent

local towerToSpawn = nil
local function MouseRaycast(blacklist)
    local mousePosition = UserInputService:GetMouseLocation()
    local mouseRay = camera:ViewportPointToRay(mousePosition.X, mousePosition.Y)
    local raycastParams = RaycastParams.new()

    raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
    raycastParams.FilterDescendantsInstances = blacklist

local raycastResult = workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000, raycastParams)


    return raycastResult
end


local function AddPlaceholderTower(name)

    local towerExists = towers:FindFirstChild(name)
    if towerExists then
        towerToSpawn = towerExists:Clone()
        towerToSpawn.Parent = workspace.Towers
    end
end

gui.Spawn.Activated:Connect(function()
    AddPlaceholderTower("Slinger")
end)

UserInputService.InputBegan:Connect(function(input, processed)
    if processed then
        return
    end

    if input.UserInputType == Enum.UserInputType.MouseButton1 then

    end
end)

RunService.RenderStepped:Connect(function()
    if towerToSpawn then
        local result =MouseRaycast({towerToSpawn})
        if result and result.Instance then
            local x = result.Position.X
            local y = result.Position.Y + towerToSpawn.Humanoid.HipHeight + (towerToSpawn.PrimaryPart.Size.Y / 2)
            local z = result.Position.Z

            local cframe = CFrame.new(x,y,z)
            towerToSpawn:SetPrimaryPartCFrame(cframe)
        end
    end
end)
0
fix formatting by editing the question, please Wiscript 622 — 1y
0
I don't really know how to fix it but does it really matter? BonkedWasTaken 0 — 1y
0
Yes it does matter. It’s so hard to read and it’s too confusing if you don’t format it properly. It’s like giving me headaches. T3_MasterGamer 2189 — 1y
0
well I don't know how to fix it tho. BonkedWasTaken 0 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

Are you sure you have a humanoid inside the Model? If yes, try Model:FindFirstChildWhichIsA("Humanoid"). Also next time format your question properly because it matters.

0
Where do I put that line of code, and also I don't know how to format my text. BonkedWasTaken 0 — 1y
0
To format your text you should see that Blue Circle with white dot in it and Lua text, press that and paste code in between Sabailuridze 126 — 1y
0
ok I fixed it, now it will be easier to understand. BonkedWasTaken 0 — 1y
Ad

Answer this question