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

UserOwner is not a valid member of Model, how to fix it?

Asked by
2ndwann 131
4 years ago
Edited 4 years ago

I am trying to make a basic placement system, and part of that is that I have to assign the owner of the item being placed. I am assigning the name of the owner to a StringValue within the item being placed.

But it does not want to do it, and it keeps giving me this error.

The error is: game.Workspace.PlacementServer:37 UserOwner is not a valid member of Model

Is there a way to fix it?

The part of the script where the trouble is happening is line #37

Server Script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local MousePositionEvent = Instance.new("RemoteEvent")
MousePositionEvent.Name = "MousePositionEvent"
MousePositionEvent.Parent = ReplicatedStorage

local PlayerFolderEvent = Instance.new("RemoteEvent")
PlayerFolderEvent.Name = "PlayerFolderEvent"
PlayerFolderEvent.Parent = ReplicatedStorage

function CreatePlayerFolder(PlayerName)
    local PlayerStructuresFolder = Instance.new("Folder")
    PlayerStructuresFolder.Name = PlayerName
    PlayerStructuresFolder.Parent = game.Workspace
end

PlayerFolderEvent.OnServerEvent:Connect(CreatePlayerFolder)

-- Structure Class
Structure = {}
Structure.__index = Structure

function Structure.new(what, owner)  
   local newStructure = {}
   setmetatable(newStructure, Structure)
   newStructure.what = what or "Nothing"
   newStructure.owner = owner or "Nobody"
   return newStructure
end

-- Place Structure
function Structure:Place(Position, RotationX, RotationY, RotationZ)
    -- Clone
    local StructureBase = self.what:Clone()
    StructureBase.Parent = game.Workspace

    StructureBase.UserOwner = self.owner -- I am having trouble with this!

    -- Preview the placement
    if(StructureBase) then
        StructureBase:MoveTo(Position)
        -- To fix
        --Structure:SetPrimaryPartCFrame(Structure:GetPrimaryPartCFrame() * CFrame.Angles(math.pi / RotationX, RotationY, RotationZ)) 
    else
        print("Error, cannot place!") 
    end
end

-- Initiate
function MovePart(Player,Coords)
    --print(Coords)
    local StructureObject = Structure.new(ReplicatedStorage.Structures.Wood.Oak.OakTable, Player)
    StructureObject:Place(Coords, 0, 0, 0)
end

MousePositionEvent.OnServerEvent:Connect(MovePart)

LocalScript:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local MouseCFrame = Mouse.Hit
local MousePosition = MouseCFrame.p

local MousePositionEvent = ReplicatedStorage:WaitForChild("MousePositionEvent")
local PlayerFolderEvent = ReplicatedStorage:WaitForChild("PlayerFolderEvent")

function ShowMousePosition()
    MouseCFrame = Mouse.Hit
    MousePosition = MouseCFrame.p
    MousePositionEvent:FireServer(MousePosition)
end

while true do
    ShowMousePosition()
    wait(0.1)
end

PlayerFolderEvent:FireServer(Player.Name)

1 answer

Log in to vote
0
Answered by
moo1210 587 Moderation Voter
4 years ago

"UserOwner is not a valid member of Model" means basicly the same as the error, UserOwner is not a vaild memeber of the model, This means you did a typo in the script, the model, or the model doesn't exist.

0
Yep, I got it fixed, thank you! 2ndwann 131 — 4y
Ad

Answer this question