I’m currently trying to make a script so that when a RemoteEvent is fired, it changes a part in the tools’ transparency and changes the name of the tool.
The error that I’m experiencing is that it ONLY works on the first few lines of script for the VanillaCupcake but doesn’t work for the rest and is not outputting any errors. Could anyone provide assistance with this?
@amadeupworld2 I’ll have to correct you. The OP is using the conditional statements correctly. Elseif is conditional keyword that refers to another case with different conditions, while else refers a case where other conditions cannot be met, resulting in this case.
@OP, your index is a problem. You cannot index with a number (Handle.Cup1). To fix this, use brackets:
Honestly, I would really recommend you do FindFirstChildOfClass("Tool") instead of what you were doing since form the looks of it, they’re tools. You’re doing a lot o repetition, so this’ll save you some lines. And for the name changing? Just remove the last 7 characters and do some concatenation to change the name for this case. Your code can be easily condensed to this
game.ReplicatedStorage.ChocIcing.OnServerEvent:Connect(function(player)
local char = player.Character
local cupcake = char:FindFirstChildOfClass("Tool")
if cupcake and cupcake.Handle:FindFirstChild("Cup1") then
cupcake.Handle.Cup1.Transparency = 0
cupcake.Handle.Cup1.BrickColor = BrickColor.new("Brown")
local name = string.gsub(cupcake.Name, " ", "")
local cupcakeWord = name:find("Cupcake")
if not cupcakeWord then return end
local flavour = name:sub(1,cupcakeWord-1)
cupcake.Name = flavour .. " ".. "Cupcake Chocolate Icing"
end
end)
Find a tool in the character, if a tool was found and it has Cup1 in its handle, change the transparency and the color and do some string changing stuff to rename the cup.
If you’re ever repeating yourself, please reach to find better ways to improve the feel of your code
Hopefully this should work, if it doesn’t, please let me know so I can try to help
Edit: Issue was on his end, the edited version works fine
You know how you edited it after you posted it? Before you edited it it worked, but once you edited it and I changed my script to the edited version it didn’t.
Oh, I think you could use the unedited version then, I think I may’ve messed up the string stuff, even though it should work. Were you referring to the fact that it wont change the name when you switched to the edited version?
Odd, I think you may’ve miscopied something? The only thing I did was just change the way it changes the name, but it wont be an issue if you can’t change icings.
If you have anymore issues don’t be afraid to make another post!