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

Why doesn't this part move into lighting?

Asked by 7 years ago
wait (0.5)
local player = game.Players.LocalPlayer
local money = player.leaderstats.Money

function onClicked(playerwhoclicked)
    money.Value = money.Value + 3
    script.Parent.Transparency = 0.1
    wait (0.1)
    script.Parent.Transparency = 0.3
    wait (0.1)
    script.Parent.Transparency = 0.5
    wait (0.1)
    script.Parent.Transparency = 0.7
    wait (0.1)
    script.Parent.Transparency = 0.9
    wait (0.1)
    script.Parent.Transparency = 1
    wait (0.1)
    script.Parent = game.Lighting
    wait (10)
    script.Parent = game.Workspace.WaterTree    
    wait (0.6)
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

The parent is a part, inside a model. The script moves into Lighting by itself.. Please explain I have no idea whats wrong! It is in a Script

0
Can you explain exactly what you're trying to do? M39a9am3R 3210 — 7y

2 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

It's actually really simple, you're moving the script into Lighting, not the parent. By saying "script.Parent = game.Lighting" you're saying that the script's new parent is lighting. To fix this, simply change it to "script.Parent.Parent = game.Lighting" and it is now will be moving the part instead of the script. I've gone ahead and edited the script to change this both when you moved the part into lighting, and back into the "WaterTree".

wait (0.5)
local player = game.Players.LocalPlayer
local money = player.leaderstats.Money

function onClicked(playerwhoclicked)
    money.Value = money.Value + 3
    script.Parent.Transparency = 0.1
    wait (0.1)
    script.Parent.Transparency = 0.3
    wait (0.1)
    script.Parent.Transparency = 0.5
    wait (0.1)
    script.Parent.Transparency = 0.7
    wait (0.1)
    script.Parent.Transparency = 0.9
    wait (0.1)
    script.Parent.Transparency = 1
    wait (0.1)
    script.Parent.Parent = game.Lighting
    wait (10)
    script.Parent.Parent = game.Workspace.WaterTree    
    wait (0.6)
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Also if I were you, to not be confused by all these Parents, I would consider using a variable for the part, just to make things a bit cleaner.

wait (0.5)
local player = game.Players.LocalPlayer
local money = player.leaderstats.Money
local part = script.Parent
function onClicked(playerwhoclicked)
    money.Value = money.Value + 3
    part.Transparency = 0.1
    wait (0.1)
    part.Transparency = 0.3
    wait (0.1)
    part.Transparency = 0.5
    wait (0.1)
    part.Transparency = 0.7
    wait (0.1)
    part.Transparency = 0.9
    wait (0.1)
    part.Transparency = 1
    wait (0.1)
    part.Parent = game.Lighting
    wait (10)
    part.Parent = game.Workspace.WaterTree    
    wait (0.6)
end

script.Parent.ClickDetector.MouseClick:connect(onClicked)

Ad
Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
7 years ago

you set script.Parent = game.Lighting, wich places the script into the lighting. use script.Parent.Parent instead.

Answer this question