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)
Scripts can't access to player gui also you need to check if the thing that touch the brick is a player try to add t ihs inside every touched function
`if hit:FindFirstChild("Humanoid") or hit.Parent:FindFirstChild("Humanoid") then
--the code
end`