Well, it seems I never get it right when it comes to returning to functions, so I'd like for you, my friends, to help me remember this. Basically what this script is, is a item equip script, for a horror game engine/framework I'm working on. When you hit F, the currently equipped light source should be welded too your arm. I scripted the functions before the KeyDown event. It doesn't seem to work, so I know I didn't recall the function right. Can anyone tell me what I'd done wrong? Code:
repeat wait() until game.Players.LocalPlayer --This is basically a anti-bug line. wait(1) --Not really needed. UseableAmmo = {[1] = script.NumTorches, [2] = script.LanternOil, [3] = script.FlashlightBattery} --A table, for my values print "Tables set" NumTorches = UseableAmmo[1] .Value LanternOil = UseableAmmo[2].Value FlashlightBattery = UseableAmmo[3].Value --I might not actually need .Value Using = script.Using Mouse = game.Players.LocalPlayer:GetMouse() --We need this print "Values set" Torch = {"Torch", NumTorches} --More tables. Lantern = {"Lantern",LanternOil} Flashlight = {"Flashlight", FlashlightBattery} print "Usable Light sources defined" wait() function GetItemUsing() --Basic, it tells us what item is equipped. wait() NowUsing = Using.Value print ("Detected that your using "..NowUsing) end function EquippItem() --Item equipping function. GetItemUsing() --So we know what item is being used. if NumTorches.Value < 1 then --We cant have nothing to equip, and still equip something NowUsing = "None" print "Out of Torches" Ocupied = true script.Error.RunOut.Visible = true --Lets tell the player that they have nothing now. script.Error.RunOut:TweenPosition(UDim2.new(0.5,0,0.75,0),"Out","Quad",4) for i=1, 60/4 do --Total Lazyness script.Error.RunOut.TextTransparency = (script.Error.RunOut.TextTransparency + (60/4)/10) --Even Lazier end script.Error.RunOut.Visible = false script.Error.RunOut.TextTransparency = 0 script.Error.RunOut.Position = UDim2.new(0.5,0,0.85,0) Ocupied = false elseif NumTorches > 1 then --If they have more than 1 if Ocupied == false then if NowUsing == "None" then print "Nothing to equip" Ocupied = true script.Error.RunOut.Visible = true script.Error.RunOut:TweenPosition(UDim2.new(0.5,0,0.75,0),"Out","Quad",4) for i=1, 60/4 do --Total Lazyness script.Error.RunOut.TextTransparency = (script.Error.RunOut.TextTransparency + (60/4)/10) --Even Lazier end script.Error.RunOut.Visible = false script.Error.RunOut.TextTransparency = 0 script.Error.RunOut.Position = UDim2.new(0.5,0,0.85,0) Ocupied = false elseif NowUsing == "Torch" then TorchW = Instance.new("Weld") --Welding time TorchW.Part0 = game.Players.LocalPlayer.Character.Torso TorchMod = game.ReplicatedStorage.TorchModel:clone() TorchW.Part1 = TorchMod TorchW.Parent = TorchMod.Arm TorchW.C0 = CFrame.new(-1,0,0)*CFrame.fromEulerAnglesXYZ(0,0,0) --game.Players.LocalPlayer.CameraMode = "Classic" --debug end end end end function KeyDown(Key) --Key down. local KeyPressed = Key:lower() if KeyPressed == "f" then if ItemEquipped == false then EquippItem() end end end Mouse.KeyDown:connect(KeyDown)
--might just need to adjust ends a little bit <pre class="brush: lua">repeat wait() until game.Players.LocalPlayer --This is basically a anti-bug line. wait(1) --Not really needed. UseableAmmo = {[1] = script.NumTorches, [2] = script.LanternOil, [3] = script.FlashlightBattery} --A table, for my values print "Tables set" NumTorches = UseableAmmo[1] .Value LanternOil = UseableAmmo[2].Value FlashlightBattery = UseableAmmo[3].Value --I might not actually need .Value Using = script.Using Mouse = game.Players.LocalPlayer:GetMouse() --We need this print "Values set" Torch = {"Torch", NumTorches} --More tables. Lantern = {"Lantern",LanternOil} Flashlight = {"Flashlight", FlashlightBattery} print "Usable Light sources defined" wait() function GetItemUsing() --Basic, it tells us what item is equipped. wait() NowUsing = Using.Value print ("Detected that your using "..NowUsing) end function KeyDown(Key) --Key down. local KeyPressed = Key:lower() if KeyPressed == "f" then if ItemEquipped == false then GetItemUsing() --So we know what item is being used. if NumTorches.Value < 1 then --We cant have nothing to equip, and still equip something NowUsing = "None" print "Out of Torches" Ocupied = true script.Error.RunOut.Visible = true --Lets tell the player that they have nothing now. script.Error.RunOut:TweenPosition(UDim2.new(0.5,0,0.75,0),"Out","Quad",4) for i=1, 60/4 do --Total Lazyness script.Error.RunOut.TextTransparency = (script.Error.RunOut.TextTransparency + (60/4)/10) --Even Lazier end script.Error.RunOut.Visible = false script.Error.RunOut.TextTransparency = 0 script.Error.RunOut.Position = UDim2.new(0.5,0,0.85,0) Ocupied = false elseif NumTorches > 1 then --If they have more than 1 if Ocupied == false then if NowUsing == "None" then print "Nothing to equip" Ocupied = true script.Error.RunOut.Visible = true script.Error.RunOut:TweenPosition(UDim2.new(0.5,0,0.75,0),"Out","Quad",4) for i=1, 60/4 do --Total Lazyness script.Error.RunOut.TextTransparency = (script.Error.RunOut.TextTransparency + (60/4)/10) --Even Lazier end script.Error.RunOut.Visible = false script.Error.RunOut.TextTransparency = 0 script.Error.RunOut.Position = UDim2.new(0.5,0,0.85,0) Ocupied = false elseif NowUsing == "Torch" then TorchW = Instance.new("Weld") --Welding time TorchW.Part0 = game.Players.LocalPlayer.Character.Torso TorchMod = game.ReplicatedStorage.TorchModel:clone() TorchW.Part1 = TorchMod TorchW.Parent = TorchMod.Arm TorchW.C0 = CFrame.new(-1,0,0)*CFrame.fromEulerAnglesXYZ(0,0,0) --game.Players.LocalPlayer.CameraMode = "Classic" --debug end end end end end end Mouse.KeyDown:connect(KeyDown) </pre>