Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Weapon System Script
- -- Setup:
- -- 1. Create Weapon Models:
- -- - Create models for each weapon type (e.g., Sword, Bow) and place them in ReplicatedStorage.
- -- 2. GUI Elements:
- -- - Create a ScreenGui in StarterGui.
- -- - Inside the ScreenGui, create a Frame for the weapon selector (WeaponFrame).
- -- - Inside the Frame, create buttons for each weapon type (SwordButton, BowButton).
- -- 3. Script Components:
- -- - Place this LocalScript inside the ScreenGui to handle weapon switching and abilities.
- local player = game.Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local replicatedStorage = game:GetService("ReplicatedStorage")
- -- GUI Elements
- local weaponFrame = player:WaitForChild("PlayerGui"):WaitForChild("ScreenGui"):WaitForChild("WeaponFrame")
- local swordButton = weaponFrame:WaitForChild("SwordButton")
- local bowButton = weaponFrame:WaitForChild("BowButton")
- local currentWeapon = nil
- -- Function to equip a weapon
- local function equipWeapon(weaponName)
- if currentWeapon then
- currentWeapon:Destroy()
- end
- local weapon = replicatedStorage:FindFirstChild(weaponName):Clone()
- weapon.Parent = character
- weapon:SetPrimaryPartCFrame(character.HumanoidRootPart.CFrame)
- currentWeapon = weapon
- end
- -- Function to use the weapon's special ability
- local function useSpecialAbility()
- if currentWeapon and currentWeapon.Name == "Sword" then
- print("Sword Special Ability: Heavy Slash")
- -- Implement heavy slash ability
- elseif currentWeapon and currentWeapon.Name == "Bow" then
- print("Bow Special Ability: Explosive Arrow")
- -- Implement explosive arrow ability
- end
- end
- -- Button connections
- swordButton.MouseButton1Click:Connect(function()
- equipWeapon("Sword")
- end)
- bowButton.MouseButton1Click:Connect(function()
- equipWeapon("Bow")
- end)
- -- Bind special ability to a key
- local userInputService = game:GetService("UserInputService")
- userInputService.InputBegan:Connect(function(input, gameProcessed)
- if gameProcessed then return end
- if input.KeyCode == Enum.KeyCode.E then
- useSpecialAbility()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement