[SOLVED - The variable SSpawn wasn't being called correctly]
I have this script that is supposed to give you different weapons depending on what button you click. The problem is, it keeps giving me the same weapons even when the actual values are different. Here is the code of the main script:
local Primary = script.Parent.Parent.Primary.Text
local Secondary = script.Parent.Parent.Secondary.Text
local Melee = script.Parent.Parent.Melee.Text
local Tools = game.ReplicatedStorage.Tools
local Player = script.Parent.Parent.Parent.Parent.Parent
local GUI = script.Parent.Parent.Parent
local BSpawn = game.Workspace.BluSpawn.Position
local RSpawn = game.Workspace.RedSpawn.Position
local BlueTeam = game.Teams.Blue
local RedTeam = game.Teams.Red
local RStorage = game.ReplicatedStorage
local PSpawn = Player.leaderstats.Primary.Value
local SSpawn = Player.leaderstats.Secondary.Value
local MSpawn = Player.leaderstats.Melee.Value
local Torso = Player.Character:findFirstChild("Torso")
local LeftLeg = Player.Character:findFirstChild("Left Leg")
local RightLeg = Player.Character:findFirstChild("Right Leg")
if Torso then Torso.BrickColor = Player.TeamColor end
if LeftLeg then LeftLeg.BrickColor = Player.TeamColor end
if RightLeg then RightLeg.BrickColor = Player.TeamColor end
-- Player Movement
Player.CameraMaxZoomDistance = 10
Player.Character.Humanoid.AutoRotate = false
Player.Character.Humanoid.WalkSpeed = 0
wait(0.1)
function leftClick()
-- Weapon Selector
if PSpawn == "M4" then
local M4 = Tools[PSpawn]:Clone()
M4.Parent = Player.Backpack
end
if SSpawn == "Glock 17" then
local G17 = Tools[SSpawn]:Clone()
G17.Parent = Player.Backpack
end
if SSpawn == "M66" then
local M66 = Tools[SSpawn]:Clone()
M66.Parent = Player.Backpack
end
-- First Person
Player.CameraMaxZoomDistance = 0.5
-- Team Spawner
if Player.Team == BlueTeam then
Player.Character.Torso.CFrame = CFrame.new(BSpawn)
end
if Player.Team == RedTeam then
Player.Character.Torso.CFrame = CFrame.new(RSpawn)
end
-- Player Movement
Player.Character.Humanoid.AutoRotate = true
Player.Character.Humanoid.WalkSpeed = 16
local MScript = RStorage.StancesScript:Clone()
MScript.Parent = Player.Character
-- Script Destroyer
GUI:Destroy()
end
script.Parent.MouseButton1Click:Connect(leftClick)
My goal here is to keep the selected weapon the same even after death, so that you don't have to choose the same weapon in the loadout menu every time you want to play.
