#Anyone know why my sound is not playing?

1 messages · Page 1 of 1 (latest)

rare plover
#

local Running = game.ReplicatedStorage.RunningEvent
local stop = game.ReplicatedStorage.stopRunning
local AccelerateSound = script.Parent["Chigiri Accelerate"]

local running = false

Running.OnServerEvent:Connect(function(plr)
game.Workspace:WaitForChild(plr.Name)
local player = game.Workspace:FindFirstChild(plr.Name)
local hum = player:WaitForChild("Humanoid")
if running == false then
running = true
while running do
wait(0.1)
hum.WalkSpeed = hum.WalkSpeed + 35
wait(3)
AccelerateSound:Play()
print("stage increased")

    end
end

end)

stop.OnServerEvent:Connect(function(plr)
game.Workspace:WaitForChild(plr.Name)
local player = game.Workspace:FindFirstChild(plr.Name)
local hum = player:WaitForChild("Humanoid")
running = false
hum.WalkSpeed = 16

end)

rare plover
#

it might be the while loop messing it

latent surge
#

You should maybe have the while true loop in a task.spawn function

timber socket
#

The script itself works "fine," which means there's a different problem whether it be where the script is located or if you got the name of something wrong, etc.

wooden juniper
#

or u just dont call the remote

rare plover
#

This script is in

#

Serverscriptstorage

#

however, the sound doesn't play

#

I want it to play every 3 seconds

#

@wooden juniper @timber socket @latent surge

wooden juniper
#

what script

#

ah wait

rare plover
#

Ok

#

lemme explain

#

so this

timber socket
#

If the script is in server script service, then the sound is too. The sound is trying to be played, but since it's in serverscriptservice it can't be

rare plover
#

O ye

#

where should i move it?>

timber socket
#

You could just move both the script and sound to startercharacterscripts and it would work

rare plover
#

Wait

#

but i am using a server script for giving speed

#

Like remote event

#

So every 3 seconds, we gain 35 more speed

#

and i want that every 3 seconds it plays the sound again

timber socket
rare plover
#

Oh

#

like

#

localscript?

#

should i put it in the localscript that fireservers?

#

look

timber socket
rare plover
#

what do you think i should do

#

i have a localscript that connects to serverscript

timber socket
#

That's fine.

rare plover
#

so how do i makie the sound play every 3 seconds

#

I hold e

timber socket
#

Like I said, the simplest solution would be to move both the script and sound to the starter character scripts, the server script not local script

rare plover
#

Ok

#

Would it cause any future problems

#

if i wanted a speed simulator or something

#

what are the benefits of using client to server remoteEvents?

timber socket
#

They're needed for the keybinding

rare plover
#

O

#

ok

#

i move it to localscript

timber socket
#

huh

#

Wdym, don't you already have the local script firing to the server?

rare plover
#

ye

#

i put it in that script

timber socket
#

put what in that script

rare plover
#

the firing to server one

#

ok so the sound does play

#

but only once

timber socket
#

I guess you could play the sound in there. Other players won't hear it though

rare plover
#

ye

#

ik

timber socket
#

Plus, that script doesn't have a loop

rare plover
#

wait

#

oh

timber socket
#

So it'll only play once

rare plover
#

do i use for

#

For

#

or While

timber socket
#

Just leave it in your other script lol

rare plover
#

Wait

#

so how do i make it play every 3 seconds i hold E

#

Cause it just plays once

timber socket
#

Like I said, all you have to do is move the server script that you have playing the sound that is currently in server script service over to starter character scripts, and also move the sound there

rare plover
#

Wait

#

why not StarterPlayer

#

scripts

timber socket
#

Starter player scripts are stored in the player object, meanwhile anything in starter character scripts gets put directly into the roblox character when it spawns

rare plover
#

if i wanted to play a sound for everyone, but only if they are close

#

do i use a humanoidRootpart

timber socket
#

You could parent the sound to the humanoid root part and use the built in properties of the sound yes

rare plover
#

wait parent the sound

#

so is sound parent or humanoidrootpart parent

timber socket
#

humanoidrootpart is parent of sound

rare plover
#

ok

#

so i would use waitforchild:Humanoidrootpart

#

on Players

#

ok but is there any way i can do all of this in a server script tho

#

in my original script

timber socket
#

Yes

rare plover
timber socket
#

I think the easiest way to do this would be to just keep a copy of the sound in replicated storage, and then clone it to the characters humanoidrootpart if it isn't there

rare plover
#

alr

#

Got it

#

what do i write in my script now

#

do i make a variable for it

#

local sound = game.ReplicatedStorage.SpeedSound?

timber socket
#

Well, if you're doing this then might as well move this script back to serverscript service. Also, yes do that

rare plover
#

ok

#

do i do instance.new("Sound")?

#

btw trying to put all of this after print("stageincreased")

timber socket
#
local Running = game.ReplicatedStorage.RunningEvent
local stop = game.ReplicatedStorage.stopRunning
local speedSound = game.ReplicatedStorage.speedSound

local running = false

Running.OnServerEvent:Connect(function(plr)
    game.Workspace:WaitForChild(plr.Name)
    local player = game.Workspace:FindFirstChild(plr.Name)
    local hum = player:WaitForChild("Humanoid")
    local humRp = player:FindFirstChild("HumanoidRootPart")
    
    if not humRp then return end
    
    local sound = humRp:FindFirstChild("speedSound")
    if not sound then
        local newSound = speedSound:Clone()
        newSound.Parent = humRp
        
        sound = newSound
    end
    
    if running == false then
        running = true
        while running  do
            wait(0.1)
            hum.WalkSpeed = hum.WalkSpeed + 35
            wait(3)
            sound:Play()
            print("stage increased")

        end
    end

end)

stop.OnServerEvent:Connect(function(plr)
    game.Workspace:WaitForChild(plr.Name)
    local player = game.Workspace:FindFirstChild(plr.Name)
    local hum = player:WaitForChild("Humanoid")
    running = false
    hum.WalkSpeed = 16

end)
rare plover
#

Ok ty

#

i testing

#

Thx

#

It works

#

btw

#

i made this script

#

it works the same

#

local Running = game.ReplicatedStorage.RunningEvent
local stop = game.ReplicatedStorage.stopRunning
local running = false
local sound = game.ReplicatedStorage.speedSound
Running.OnServerEvent:Connect(function(plr)
game.Workspace:WaitForChild(plr.Name)
local player = game.Workspace:FindFirstChild(plr.Name)
local hum = player:WaitForChild("Humanoid")
if running == false then
running = true
while running do
wait(0.1)
hum.WalkSpeed = hum.WalkSpeed + 60
wait(3)
print("stage increased")
sound.Parent = player:WaitForChild("HumanoidRootPart")
sound:Play()

    end
end

end)

stop.OnServerEvent:Connect(function(plr)
game.Workspace:WaitForChild(plr.Name)
local player = game.Workspace:FindFirstChild(plr.Name)
local hum = player:WaitForChild("Humanoid")
running = false
hum.WalkSpeed = 16

end)

#

@timber socket

#

is there any differences between my script and urs?

timber socket
#

Yours doesn't clone the sound, so it wouldn't work if multiple different players try to use the ability or if your character dies

rare plover
#

oh

#

ok

#

would this work now

#

Also kruz

#

if i hold e for even 1 second

#

it still plays the sound 3 seconds later

#

@timber socket

#

this also happens in ur script

timber socket
#

well yes

#

I just edited yours

rare plover
#

how would i fix it

timber socket
#

just put an if then statement checking if running is equal to true, and if it is, continue to play the sound

rare plover
#

ohh

#

so it checks again right? @timber socket

timber socket
#

yeah, just after the 3 second wait

rare plover
#

alr it works

#

ty

#

Btw

#

how long have you been scripting?

#

@timber socket

timber socket
#

On and off since 2017, so I'm not quite sure the exact time

rare plover
#

Oh ok

#

nice

#

have you made any gamess?

timber socket
#

Not any published

rare plover
#

o

#

you know how i also make it dash forward every 3 seconds?

#

nvm

#

my work here is done

#

ty

#

i will get someone else to help

#

you helped enough