These 3 scripts(not made by me) work In test mode however when I tried actually playing the game the scripts would not work. What is wrong with these scripts?

Song Player script. Is placed in starter gui

local this = {}

--> Setting up values
local musicNow = script.song.Value
local songPitch = 1
local songVolume = 0.6
local player = script.Parent.Parent

--FUNCTION> Setup the initial values, play the first song, etc.
function this.Setup()
	if player:findFirstChild("SongPlayerData")==nil then
		--Create data that loads on respawn
		local b = Instance.new("BoolValue")
		b.Name = "SongPlayerData"
		b.Parent = player
		local o = Instance.new("StringValue")
		o.Name = "SongPlay"
		o.Parent = b
		local v = Instance.new("NumberValue")
		v.Name = "Volume"
		v.Value = songVolume
		v.Parent = b
	else
		--Load the data on respawn
		songVolume = player.SongPlayerData.Volume.Value
		if player.SongPlayerData.SongPlay.Value ~= nil then
			local find = script.Music:findFirstChild(player.SongPlayerData.SongPlay.Value)
			if find == nil then return end
			script.song.Value = find
			musicNow = script.song.Value
			musicNow.Pitch = songPitch
			musicNow.Volume = songVolume
			musicNow:Play()
		end
	end
end

--FUNCTION> Find the song name that was called, & play it
function this.PlaySong(so)
	local ss = script.Music:findFirstChild(so)
	if ss == nil then return end
	if musicNow == ss then return end
	if musicNow ~= nil then musicNow:Stop() end
	script.song.Value = ss
	musicNow = script.song.Value
	musicNow.Pitch = songPitch
	musicNow.Volume = songVolume
	musicNow:Play()
	player.SongPlayerData.SongPlay.Value = so 
	--^Makes the current song play again on respawn. Delete this if you want to set that manually.
end

--FUNCTION> Stop the music.
function this.StopSong()
	if musicNow == nil then return end
	musicNow:Stop()
	script.song.Value = nil
	musicNow = nil
	player.SongPlayerData.SongPlay.Value = ""
	--^This will make it so music will not play if you respawn after stopping.
end

--FUNCTION> Set the speed of the music playing.
function this.SetPitch(pit)
	songPitch = pit
	if musicNow == nil then return end
	musicNow.Pitch = songPitch
end

--FUNCTION> Set the volume of the music playing.
function this.SetVolume(vol)
	songVolume = vol
	if musicNow == nil then return end
	musicNow.Volume = songVolume
end

return this

initialize script- Placed in side Song player script

local mScript = require(script.Parent)
mScript.Setup()
wait()
script:destroy()

Playsong script is inside a block which when touched will play a song inside the Music Frame. Music Frame is placed inside Song Player script.

function onTouched(hit)
	
	if hit.Parent == nil then return end
	local h = hit.Parent:FindFirstChild("Humanoid")
	if h==nil then return end
	local p = game.Players:findFirstChild(h.Parent.Name)
	if p == nil then return end
	local mScript = require(p.PlayerGui.SongPlayer)
	mScript.PlaySong(script.Parent.playThis.Value)
	
end

connection = script.Parent.Touched:connect(onTouched)

I hope this is enough info to help me out on this.

1 comment

0

The same thing is happening with me on my server time GUI script