I'm new to scripting, and I have no clue how to start this..
How do I make a ImageButton that when you click it, a model get spawned in front of the player?
2 answers
So, first you should have the model you want to clone inside of game.ReplicatedStorage. Don't use lighting, since that isn't meant for storing stuff, obviously. You also shouldn't use ServerStorage, since we're going to be coding in a localscript.
First, create a "RemoteEvent" and put it in ReplicatedStorage. RemoteEvent is what's used to have the server communicate with the client. (and vise versa)
Next, put this in a ServerScript inside ServerScriptService (Never put normal scripts in workspace)
local model = game.ReplicatedStorage.name -- Change name to the model's name, please note that it can't have spaces in it.
function spawnModelForPlr(plr)
local character = plr.Character
local newModel = model:Clone()
newModel.Parent = game.Workspace
newModel:MoveTo((character.Head.CFrame * CFrame.new(0, 0, -10)).p) -- this moves it 10 studs infront of the player.
end
game.ReplicatedStorage.RemoteEvent.OnServerEvent:connect(spawnModelForPlr)
Next, put a LocalScript inside of the TextButton you've created. Inside it, have this code:
local button = script.Parent -- if the script isn't inside of the textbutton, change the directory here
button.MouseButton1Click:connect(function()
game.ReplicatedStorage.RemoteEvent:FireServer()
end)
8 comments
I am making an actual game. And it doesn't seem to work.
Nevermind. It does work. :D
Excuse me, Not the be rude but where you said "please note that it can't have spaces in it." It actually can.
For an example if the name of it was "Cool Stuff", you would do local model = game.ReplicatedStorage["Cool Stuff"] Just a tip.
The only problem is, it's fully local. Other players can't see the parts I spawn.
I know that you can have spaces by using [], I was just trying to make it simpler.
I changed the code so that it's filtering support.
Hmmm... It doesn't seem to be working. Nothing happens when I click the ImageButton.
Well Here Is What You Want To Do:
script.Parent.MouseButton1Click:connect(function()
local Part = Instance.new("Part")
Part.Position = 0, 0, 0
Part.Color = 255,255,255
Part.Refletance = 2
Part.CanColide = false
Keep Repeating It With Different Part Names At Local Instead Of Part Next Time Do Part2,Part3 etc. Make Sure This Is In a Local Script In The Image Button.
3 comments
@jamiethegreatQ7
He said he wanted a model, not a part. This code is full of problems that i'm not even going to get into, just, no.
You don't have an end on the function, no Vector3.new() no Color3.fromRGB() and you never parent the part. It also only spawns at 0,0,0 (of course it wouldn't because of all the errors) but that doesn't get anywhere near the player Character.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
Do you have the textbutton set up already?
Sorry, I meant ImageButton. I will edit it now, and yes, I have.
Alright, let me write an answer real quick.