Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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.

2 comments

0

is it in a LocalScript?

0

Yes it is in a local script, it would not work otherwise.

1 answer

✓ Accepted answer

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 comment

1

Ok thx so much dude.

This discussion is preserved as it was. New answers, comments, and votes are closed.