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

How can I insert a sound into a player, and then play it when they click a gui button?

Asked by 4 years ago
local button = script.Parent
local client = game:GetService("Players").LocalPlayer
local character = client.Character or client.CharacterAdded:Wait()
local no = game.ServerStorage.Sound
local clone = no:Clone()
clone.Parent = character.Head
local sound = character.Head:WaitForChild("Sound")
button.Activated:Connect(function()
    if not sound.IsPlaying then 
        character.Humanoid.WalkSpeed = 90
        sound:Play()
        sound.Looped = true
        button.Text = 'SLOW DOWN!'
    else
        character.Humanoid.WalkSpeed = 16
        sound:Stop() 
        sound.Looped = false
        button.Text = 'RUN FAST!'
    end
end)

This script doesn't create errors, it just doesn't work. It is meant to insert a sound into a player, then play it when they click it.

0
is it in a LocalScript? KDarren12 705 — 4y
0
Yes it is in a local script, it would not work otherwise. Just_Moop 27 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago

ServerStorage is a service. It should be called by

game:GetService("ServerStorage")

and not

game.ServerStorage

Firstly I recommend using ReplicatedStorage instead of ServerStorage for items that localscripts require. For example:

local repStorage = game:GetService("ReplicatedStorage")
local sound = repStorage:WaitForChild("Sound")

Otherwise, I believe the rest of the script should function correctly.

1
Ok thx so much dude. Just_Moop 27 — 4y
Ad

Answer this question