i have this script that i want to make clone an audio if a player touches a brick, but it says player is nil, also I want it to make the audio's volume 0 if they touch a certain brick
local Players = game:GetService("Players")
local clone = workspace.gluesound:Clone()
local floor2 = workspace:WaitForChild("Floor2")
local debounce = false
local player
local getPlayerFromCharacter
getPlayerFromCharacter = function(model)
local plr = Players:GetPlayerFromCharacter(model)
if plr then --checking if player
return plr
else
return nil
end
end
------play the audio and clone it if the player touches-----
script.Parent.Touched:Connect(function(hit)
if not debounce then
debounce = true
local player = getPlayerFromCharacter(hit.Parent)
clone.Parent = player.PlayerGui
clone.Volume = 0.1
wait(1)
debounce = false
end
--floor2 is the brick i want to stop the music
floor2.Touched:Connect(function(hit)
if not debounce then
debounce = true
local player = getPlayerFromCharacter(hit.Parent)
player.PlayerGui.gluesound.Volume=0
wait(1)
debounce = false
end
end)
-- so is the brick 'yess'
workspace.yess.Touched:Connect(function(hit)
if not debounce then
debounce = true
local player = getPlayerFromCharacter(hit.Parent)
player.PlayerGui.gluesound.Volume=0
wait(1)
debounce = false
end
end)
end)

2 comments
Placing a sound in PlayerGui and playing it from a Script will not play locally; it will play to the server. Use a RemoteEvent or use LocalScripts to play locally.
how could I make it so that it activates only when the local player touches it