Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to play music locally if a player touches a brick?

Asked by 6 years ago
Edited 6 years ago

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)
0
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.  User#19524 175 — 6y
0
how could I make it so that it activates only when the local player touches it retracee 68 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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`

Ad

Answer this question