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

Car not getting placed in workspace?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

When I click a textbutton, I want "Koenigsegg One:1" to clone into workspace and hover over the player that click the button head, it does not clone though.

script.Parent.MouseButton1Click:connect(function()
    game.Players.PlayerAdded:connect(function(plr)
        plr.CharacterAdded:connect(function(char)
            local C = game.ReplicatedStorage.Cars:WaitForChild("Koenigsegg One:1"):Clone()
            C.Parent = game.Workspace
            C:MoveTo(char.HumanoidRootPart.Position + Vector3.new(3, 0, 3))
        end)
    end)
end)

Thanks if you help me :)

0
PlayerAdded doesn't work in a localscript. rexbit 707 — 8y
0
This is a normal script though FiredDusk 1466 — 8y
0
It doesn't clone because you never actually clone it. You just connect the events (Player- and CharacterAdded). But you don't need the events, just get rid of them. And you should ALWAYS use a LocalScript when working with GUIs. Perci1 4988 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

This is a GUI, you use localscripts for GUIs. Make your script a local script then use the script bellow, under the script is the explanation.

local plr = game.Players.LocalPlayer
repeat wait() until plr.Character -- wait for player to not be nil, then make the variable of it bellow
local char = plr.Character

script.Parent.MouseButton1Click:connect(function()
         local C = game.ReplicatedStorage.Cars:WaitForChild("Koenigsegg One:1"):Clone()
         C.Parent = game.Workspace
         C:MoveTo(char.HumanoidRootPart.Position + Vector3.new(3, 0, 3))
end)

You were using Events in an event in an event, two of which (PlayerAdded/CharacterAdded) wouldn't fire just because you press the button. I'm not even sure what would happen. Comment any questions if you need further explanations or errors occur!

0
The car is anchored when it is not suppose to be. FiredDusk 1466 — 8y
Ad
Log in to vote
-1
Answered by 8 years ago

Using localscripts would speed up things..

0
Suggestions should be comments alphawolvess 1784 — 8y

Answer this question