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

How do I make the elseif work and the rotation from just changing the Y value only?

The sound id is fixed since the ULR was messed up Thanks to Spongocardo. But, I added another elseif with it, but that didn't work either. I also thought using CFrame.new will work for the Rotation to make it only rotate the Y-axis and not the X and Z. But apparently, they only allow it on Vector3.new() This is the script:

Edited

local tune = game.Workspace.Radio.Tune
sound = Instance.new("Sound", tune)
debounce = false

function onClicked()
	if not debounce then
	debounce = true
		tune.Rotation = Vector3.new(89.98, -69.598, 89.98)
		sound.SoundId = "rbxassetid://142295308"
		sound:Play()
	elseif debounce then
		sound:Stop()
		tune.Rotation = Vector3.new(89.999, -51.347, 90)
		sound.SoundId = "rbxassetid://209864226"
		sound:Play()
	elseif debounce then
		sound:Stop()
		tune.Rotation = Vector3.new(89.98, -89.282, 89.98)
		print("Off")
	debounce = false
	end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

I want the Vector3.new() to be like this almost where I only change the Y only. Like this Vector3.new(X, -69.598, Z). Like this is what I mean. So, is there a CFrame for this to work or something?

4 comments

0

Line 19 and 13 work on the same Condition and debounce only ends on the elseif for 19

0

So, how do I fix it

0

Try using rbxassetid:// then the id instead of the other id bit on lines 9 and 15. So it would look like this: "rbxassetid://209864226"

0

Okay, I will try. But what about the elseif part.

1 answer

✓ Accepted answer

Since I've already solved the sound problem in the comments, I will go straight to the rotation problem.

If you want to make it so only the Y value changes, you can just use the tune part's X and Z values for the Rotation as the arguments for the new Vector3.

local tune = game.Workspace.Radio.Tune
sound = Instance.new("Sound", tune)
debounce = false

function onClicked()
    if not debounce then
    debounce = true
        tune.Rotation = Vector3.new(tune.Rotation.X, -69.598, tune.Rotation.Z)
        sound.SoundId = "rbxassetid://142295308"
        sound:Play()
    elseif debounce then
        sound:Stop()
        tune.Rotation = Vector3.new(tune.Rotation.X, -51.347, tune.Rotation.Z)
        sound.SoundId = "rbxassetid://209864226"
        sound:Play()
    elseif debounce then
        sound:Stop()
        tune.Rotation = Vector3.new(tune.Rotation.X, -89.282, tune.Rotation.Z)
        print("Off")
    debounce = false
    end
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

For your elseif problem, you've got two problems. The first one is that you never change debounce to false until line 20, which will never happen as line 11 will execute first, which is the second problem.

You can add to the other two if statements to check if the radio is on and the SoundId is equal to one of the SoundIDs and then run the different block of code like so:

local tune = game.Workspace.Radio.Tune
sound = Instance.new("Sound", tune)
debounce = false
radioOn = false

function onClicked()
	if debounce then return end --Stop the function if debounce is true.
	debounce = true
	if not radioOn then
		radioOn = true
		tune.Rotation = Vector3.new(tune.Rotation.X, -69.598, tune.Rotation.Z)
		sound.SoundId = "rbxassetid://142295308"
		sound:Play()
	elseif radioOn and sound.SoundId == "rbxassetid://142295308" then
		sound:Stop()
		tune.Rotation = Vector3.new(tune.Rotation.X, -51.347, tune.Rotation.Z)
		sound.SoundId = "rbxassetid://209864226"
		sound:Play()
	elseif radioOn and sound.SoundId == "rbxassetid://209864226" then
		radioOn = false
		sound:Stop()
		tune.Rotation = Vector3.new(tune.Rotation.X, -89.282, tune.Rotation.Z)
		print("Off")
	end
	debounce = false
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

I hope my answer helped you. If it did, be sure to accept it.

1 comment

0

I clicked the tune part and it rotated to -69.598. But when I clicked it again it didn't rotate to -51.347. The tune is like supposed to be where people can like channel it around to find there favorite song or something. But, anyway, thanks for helping me out man!

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