So, what I'm trying to do is make so that I can spawn a prop from my props folder/models. I've already figured out how to make it work by using server scripts, but I want to make it spawn one when I press C. Here is the my propAPIMain script inside my ServerScriptStorage. I don't need it to be FilteringEnabled right now, thats not what I'm trying to do.
--Made by dudemanjude print '[PropAPI] Starting up.' p = game.ServerStorage.PropAPI.Props --This is the function I used for spawning the props with the server scripts. _G.spawnProp = function(propName, pos) local prop = findProp(propName):Clone() print("[PropAPI] Spawning prop: " .. prop.Name) prop:MoveTo(pos) prop.Parent = workspace end --This function is for spawning with client scripts. workspace.spawnProp.OnServerInvoke = function(propName, pos) local prop = findProp(propName):Clone() print("[PropAPI] Spawning prop: " .. prop.Name) prop:MoveTo(pos) prop.Parent = workspace end function findProp(propName) for i, prop in ipairs(p:GetChildren()) do if prop.Name == propName then return prop end end end
Now here is the script for making the prop spawn when I press C. This script is inside of the StarterPack.
--Made by dudemanjude mouse = game.Players.LocalPlayer:GetMouse() spawnKey = "c" cP = game.Players.LocalPlayer.Character.Torso.Position + Vector3.new( 0,10,0 ) mouse.KeyDown:connect(function( key ) if key == spawnKey then workspace.spawnProp:InvokeServer("crate_01", cP) end end)
The error I keep getting is this: 17:23:17.744 - ServerScriptService.propAPIMain:13: attempt to index a nil value 17:23:17.745 - Script 'Players.Player1.Backpack.crateSpawn', Line 9 17:23:17.746 - Stack End 17:23:17.746 - Disconnected event because of exception
I've tried many things, but they just won't work. Thanks, dudemanjude.