Hi! I’m new to scripting and need a bit of help.
I made a GUI that has buttons, and when a player presses a button, they are supposed morph into the model that corresponds with that button. But I have no idea how to do that…
Example:
the “Hi” button will morph you into the “Hi” morph
the “Bye” button will morph you into the “Bye” morph… etc
So if anyone can help me out with this, it would be very appreciated!
Thanks!
These are the morphs that I’m talking about. They are morphs that are made to fit above a character. But I’m not sure what would be the best way to do this.
If that doesn’t work for you then, maybe try making buttons that when you step on you morph. Sorry if I’m not such a big help I don’t know much about scripting morph gui or buttons.
-- Place this code in a LocalScript in a TextButton
local textButton = script.Parent
local MorphEvent = game.ReplicatedStorage:WaitForChild("MorphEvent")
-- Here, we define a function
local function onActivated()
-- This will send the server a message
MorphEvent:FireServer('Hi')
end
-- Connect the "Activated" event to our function
textButton.Activated:Connect(onActivated)
And the server sided Script would be something like
local ReplicatedStorage = game.ReplicatedStorage
local MorphEvent = Instance.new("RemoteEvent", ReplicatedStorage)
MorphEvent.Name = "MorphEvent"
function onMorphEventFired(callingPlayer, requestedMorphName)
print(player.Name, "wants to morph into a ",requestedMorphName)
if requestedMorphName == "Hi" then -- Always good to have some sort of check
-- Create a clone of the body
local newBody = game.ServerStorage:FindFirstChild('Hi'):Clone()
-- Move the new body to where the player is standing
newBody:MoveTo(callingPlayer.Character.HumanoidRootPart.Position)
-- Set the model as the character's body
callingPlayer.Character = newBody
end
end
MorphEvent.OnServerEvent:Connect(onMorphEventFired)
This code is untested but it should give you a basic idea of how to do this.
Another question, since I’m super new to scripting, the Script (not local) would go where?
And also, where would I put the model in the script? Like how does it know which one it’s using?
Do you have a discord where I can speak about this more?