Hello everyone!
Before explaining you my issue, I would like to let you know that I'm new in scriptinghelpers and also new in Lua, I'm happy to start now this site to understand better how to use Lua for scripting and making games in Roblox! Sorry already if I did one or many mistakes during explaining my issue D:
So, I recently started to create a Roblox game where it's gonna be like a guide (Helping new players, explaining the story of Roblox...), no problem right now, until getting blocked with a ScreenGui with 3 ImageButton...
Let me explain, I did create 3 ImageButtons with each one a feature (One for making the player running with 32 studs/s or walking with 16 studs/s , one to On/Off the music and the last one for Mute/Unmute the boomboxes) so it can be useful for the players, but I'm unfortunately blocked on these ImageButtons, because in fact, I'm trying to do this : When a player click on the running ImageButton (for example), the BackgroundColor3 changes to green (red by default) AND makes the players moving 32 studs/s (So the double), the problem is that I did a LocalScript for each ImageButton (Because I want only for the player and not directly all the players) but I can't find the thing I have done wrong :/
Here is the current code of my Running ImageButton :
--Makes a sound when the mouse touches an image
script.Parent.MouseEnter:Connect(function()
script.Parent.Parent.Parent.Enabled = true
script.ClickSound:Play()
end)
--Makes the BackgroundColor3 AND CharacterWalkSpeed to change when clicked
button = script.Parent
off = button.BackgroundColor3
on = Color3.fromRGB(108, 246, 50)-- Green
speedOn = game.StarterPlayer.CharacterWalkSpeed == 32 -- Double speed
speedOff = game.StarterPlayer.CharacterWalkSpeed == 16 -- Default speed
speed = game.StarterPlayer.CharacterWalkSpeed
script.Parent.MouseButton1Click:Connect(function()
if speed == speedOff then
button.BackgroundColor3 = on and speed == speedOn
elseif button.BackgroundColor3 == on and speed == speedOn then
button.BackgroundColor3 = off and speed == speedOff
end
end)
When I try my game with this script for the running feature, the MouseEnter works (So It makes a sound when the mouse touches it) but it doesn't change the BackgroundColor3 and CharacterWalkSpeed neither when I click it...
I tried yesterday with only one feature (The one that it changes the color when clicked) with this LocalScript and it worked :
--Makes a sound when the mouse touches an image
script.Parent.MouseEnter:Connect(function()
script.Parent.Parent.Parent.Enabled = true
script.ClickSound:Play()
end)
--Makes the BackgroundColor3 AND CharacterWalkSpeed to change when clicked
button = script.Parent
off = button.BackgroundColor3
on = Color3.fromRGB(108, 246, 50)-- Green
speedOn = game.StarterPlayer.CharacterWalkSpeed == 32 -- Double speed
speedOff = game.StarterPlayer.CharacterWalkSpeed == 16 -- Default speed
speed = game.StarterPlayer.CharacterWalkSpeed
script.Parent.MouseButton1Click:Connect(function()
if button.BackgroundColor3 == off then
button.BackgroundColor3 = on
elseif button.BackgroundColor3 == on then
button.BackgroundColor3 = off
end
end)
So I think that I am doing something wrong with the first code to add two feature with only one LocalScript in it (Maybe the one to change the player's speed is the cause of the problem, because to be honest, It's possibly because I'm trying to change the speed with the wrong way )...
Anyway! So my question is : Can I add two features (Changing the Backgroundcolor3 of the ImageButton and changing the CharacterWalkSpeed) with only one LocalScript in the running ImageButton ? If yes, can you explain me how ? It would be really awesome and nice, also, it will maybe help scripters that they have the same issue like me :D
Sorry again if this question was already asked before, I did ask here because I couldn't find a similar issue like mine (Or maybe I didn't search well :( )
Thank you in advance for the future help and the answer! I wish you all a good time and having fun making new things to Roblox!
