MY code:
sword = game.Lighting.ClassicSword debounce = false local function onTouch(Object) if (debounce ~= false) then return end debounce = true local char = Object.Parent:FindFirstChild("Humanoid") if (char ~= nil) then local play = game.Players:GetPlayerFromCharacter(Object.Parent) if (play ~= nil) then game.Workspace.stairswplat.capsule = game.Lighting game.Lighting.opencapsule = game.Workspace local swordc = sword:Clone() swordc = play.Backpack wait(1) game.Lighting.capsule = game.Workspace game.Workspace.stairswplat.opencapsule = game.Lighting wait(.5) end end debounce = false end script.Parent.Touched:connect(onTouch)
As you know, the Lighting folder is basically a store pile for things that aren't in the game. This script... I want it to exchange the capsule with the opencapsule through the Lighting folder. When you touch the model, specifically the middle of the capsule where the script is placed, the capsule model is exchanged with the opencapsule, and a sword is inserted into the player's backpack also from the lighting folder. But the error is "capsule is not a valid member of Model". None of my models are named Model. Help!
The error message is telling you that the variable is of type "Model", not that it's named "Model". On line 11+, you're not allowed to do whatever it is you're trying to do. I think you mean to change the parent of each object, ex game.Workspace.stairswplat.capsule.Parent = game.Lighting
(same idea on lines 12, 14, 16, and 17)
Stylistic notes:
if debounce ~= false then return end
(you can also do if debounce then return end
, in this case). Similarly, for line 7 you can just say if char then
-- in Lua, any value that isn't false
or nil
is considered true
in boolean logic.