Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make a ImageButton that when you click it, a model get spawned in front of the player?

Asked by 6 years ago
Edited 6 years ago

I'm new to scripting, and I have no clue how to start this..

0
Do you have the textbutton set up already? User#8349 0 — 6y
0
Sorry, I meant ImageButton. I will edit it now, and yes, I have. sebse456 13 — 6y
0
Alright, let me write an answer real quick. User#8349 0 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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)

0
I am making an actual game. And it doesn't seem to work. sebse456 13 — 6y
0
Nevermind. It does work. :D sebse456 13 — 6y
0
Excuse me, Not the be rude but where you said "please note that it can't have spaces in it." It actually can. IIApexGamerII 76 — 6y
0
For an example if the name of it was "Cool Stuff", you would do local model = game.ReplicatedStorage["Cool Stuff"] Just a tip. IIApexGamerII 76 — 6y
View all comments (4 more)
0
The only problem is, it's fully local. Other players can't see the parts I spawn. sebse456 13 — 6y
0
I know that you can have spaces by using [], I was just trying to make it simpler. User#8349 0 — 6y
0
I changed the code so that it's filtering support. User#8349 0 — 6y
0
Hmmm... It doesn't seem to be working. Nothing happens when I click the ImageButton. sebse456 13 — 6y
Ad
Log in to vote
-1
Answered by 6 years ago

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.

If It Does Not Work For You Please Tweet Me

0
@jamiethegreatQ7 JamiethegreatQ777 16 — 6y
1
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. User#8349 0 — 6y
0
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. theCJarmy7 1293 — 6y

Answer this question