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

How to make this while true do question work?

Asked by 4 years ago

I want to make a tycoon game but the script is not working. every time I try to test the game it just freezes and I don't know why.

while true do
    script.Parent.Mouseclick:Connect(function()
    chair = game.Workspace.Chair:Clone()
    chair.Position = game.Players.LocalPayer.Mouse()
end

what is wrong help me.

0
You have to get the mouse first User#25281 0 — 4y
0
What on earth are you trying to do MachoPiggies 526 — 4y
0
sigh BashGuy10 384 — 4y

2 answers

Log in to vote
1
Answered by
Elixcore 1337 Moderation Voter
4 years ago

Several problems with this.

1st problem. You are listening to an event inside the loop. 2nd problem. you never end the event. 3rd problem. you're cloning the chair each time. 4th problem. you're not setting the clone's parent. 5th problem. player.Mouse() is not a valid way to obtain mouse. 6th problem. Mouse is not a Vector3 Value.

Get rid of the loop, Connect to the event properly, actually close it, create the clone outside of the event, set its parent, set its position inside the event, you can obtain mouse by using player:GetMouse(), to get its position you do mouse.Hit.Position

Ad
Log in to vote
0
Answered by
bluzorro 417 Moderation Voter
4 years ago
Edited 4 years ago

You need to add a wait() at the end of the while loop because while loops are executed at the fastest speed and that's what made your game freeze. Also, you have spelled MouseClick wrong. It's supposed to have a capital M and C. Here's a better version of what you tried to do:

local mouse = game.Players.LocalPlayer:GetMouse()

while true do
    script.Parent.MouseClick:Connect(function()
        local chair = game.Workspace.Chair:Clone()
        chair.Position = mouse.Hit.p
    end)
    wait()
end
0
not a better version, delete this. Elixcore 1337 — 4y

Answer this question