I have an Issue with a tool I made, a guitar tool for future RP projects. As a person with no experience about LUA coding language, with tutorials in youtube and with some rookie scripters. This is the best I've done so far.
local player = game.Players.LocalPlayer
local localMouse = player:GetMouse()
local songs = {
[1] = script.Parent.Handle.Acoustic1,
[2] = script.Parent.Handle.Acoustic2,
[3] = script.Parent.Handle.Acoustic3,
[4] = script.Parent.Handle.Acoustic4
}
local song = songs[math.random(1,#songs)]
local GuitarON = false
local animation = game.Players.LocalPlayer.Character:FindFirstChild("Humanoid"):LoadAnimation(script.Parent.Playing)
localMouse.Button1Down:Connect(function()
if script.Parent.IsEquipped.Value == true then
if GuitarON == false then
GuitarON = true
song:Play()
animation:Play()
elseif GuitarON == true then
GuitarON = false
song:Stop()
animation:Stop()
end
end
end)
local plr = game:GetService("Players").LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
local h = char:WaitForChild("Humanoid")
local anim = h:LoadAnimation(script.Parent:WaitForChild("Handling"))
local tool = script.Parent
tool.Equipped:Connect(function()
anim:Play()
end)
tool.Unequipped:Connect(function()
anim:Stop()
song:Stop()
animation:Stop()
end)
The Issue is, when the tool has been equipped from where it has been placed, each time I click on mouse It plays the same music over and over. Even though, I did
local songs = {
[1] = script.Parent.Handle.Acoustic1,
[2] = script.Parent.Handle.Acoustic2,
[3] = script.Parent.Handle.Acoustic3,
[4] = script.Parent.Handle.Acoustic4
}
local song = songs[math.random(1,#songs)]
There are four songs in math.Random and only plays a single one each time clicked on mouse1.
What is the Issue that I do not see? Don't try to explain it to me because, I can barely cope with scripting explanations right now. I need visual examples to understand.

1 comment
You have to select a random song each time you activate the tool. Line 11 is a static assignment.