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

Model Spawner GUI?

Asked by
steev 0
9 years ago

I have put the model into Lighting. I want the model to spawn in front of the player when they click the GUI. When i have tested this it doesn't seem to work.

script.Parent.MouseButton1Click:connect(function()
c = game.Lighting["Horse"]:Clone() --edit this line here
c.Parent = game.Workspace
c:MoveTo(character.Torso.Position + Vector3.new(0,0,10))
end)

Any help?

0
Wow, I made nearly the exact same script for a friend's game... What's the error? I don't think you can make the horse spawn in front of the player without using look vector and I don't know how to use it. M39a9am3R 3210 — 9y

2 answers

Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
9 years ago

I see your problem, you never defined the character on line 4, if you don't do that then the horse will not be moved and you get the error "Players.Player1.PlayerGui.ScreenGui.TextButton.Script:4: attempt to index global 'character' (a nil value)".

The below script is assuming the button is inside of a frame.

script.Parent.MouseButton1Click:connect(function()
c = game.Lighting["Horse"]:Clone() --edit this line here
c.Parent = game.Workspace
c:MoveTo(script.Parent.Parent.Parent.Parent.Character.Torso.Position + Vector3.new(0,0,10))
end)

I would highly recommend you add a spam prevention feature to the script as well.

Ad
Log in to vote
0
Answered by 9 years ago

I would use a weld to weld it to the player and if that's done. Remove the weld. The Model is now in front of the player. For this script you'll have to add the horse model to ServerStorage in order to work.

local player = game.Players.LocalPlayer
local character = player.Character
script.Parent.MouseButton1Click:connect(function()
    c = game.ServerStorage["Horse"]:Clone()
    c.Parent = game.Workspace
    c.PrimaryPart = c:FindFirstChild("Part")-- Change this to what you want to be the primary part of the horse model.
    local weld = Instance.new("Weld", c.PrimaryPart) -- Create a new weld
    weld.Part0 = character.Torso -- Add the weld to the Torso
    weld.Part1 = c.PrimaryPart -- And to the models primary part
    weld.C0 = CFrame.new() -- Take the weld.Part0s CFrame
    weld.C1 = CFrame.new(0, 2, 3) -- And give weld.Part1 an offset to spawn in front
    wait() -- Wait for it
    weld:Destroy() -- And destroy the weld
end)

And don't forget that this script should be executed from a LocalScript.

Answer this question