So i’m working on something that when a player clicks a button that the first clone gets cloned.
But when the player clicks it for the second time the other model needs to be cloned but that doesnt works.
Here’s the script;
local hover = game.SoundService.HoverSound
script.Parent.MouseEnter:Connect(function()
hover:Play()
end)
local player = game.Players.LocalPlayer
local Cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
local leaderstats = player.leaderstats
script.Parent.MouseButton1Click:Connect(function()
local second = false
script.Parent.PurchaseScript.Disabled = true
print("Script Disabled!")
Cash.Value = Cash.Value - 500
script.Parent.Parent.Visible = false
wait(2.5)
if second == false then
local tvmakerclone1 = game.ReplicatedStorage.TvMakers.TvMakerLVL1:Clone()
tvmakerclone1.Parent = game.Workspace
second = true
else
--here needs to be the second clone
print("LOL")
end
wait(30)
script.Parent.PurchaseScript.Disabled = false
print("Script has been enabled!")
end)
if not game.Workspace:FindFirstChild("TvClone1") then
local tvmakerclone = game.ReplicatedStorage.TvMakers.TvMakerLVL1:Clone()
tvmakerclone.Name = "TvClone1"
tvmakerclone.Parent = game.Workspace
elseif game.Workspace:FindFirstChild("TvClone1") and not game.Workspace:FindFirstChild("TvClone2") then
local tvmakerclone = game.ReplicatedStorage.TvMakers.TvMakerLVL1:Clone()
tvmakerclone.Name = "TvClone2"
tvmakerclone.Parent = game.Workspace
end
If there is multiple clones for each players, you can change that:
tvmakerclone.Name = Player.Name… “TvClone1”
if not game.Workspace:FindFirstChild(Player.Name… “TvClone1”) then
local hover = game.SoundService.HoverSound
script.Parent.MouseEnter:Connect(function()
hover:Play()
end)
local player = game.Players.LocalPlayer
local Cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
local leaderstats = player.leaderstats
local second = false
script.Parent.MouseButton1Click:Connect(function()
script.Parent.PurchaseScript.Disabled = true
print("Script Disabled!")
Cash.Value = Cash.Value - 500
script.Parent.Parent.Visible = false
wait(2.5)
if second == false then
local tvmakerclone1 = game.ReplicatedStorage.TvMakers.TvMakerLVL1:Clone()
tvmakerclone1.Parent = game.Workspace
second = true
else
--here needs to be the second clone
print("LOL")
end
wait(30)
script.Parent.PurchaseScript.Disabled = false
print("Script has been enabled!")
end)
Yes
Also, you should use a script instead of local script.
script.Parent.MouseButton1Click:Connect(function()
script.Parent.PurchaseScript.Disabled = true
Cash.Value = Cash.Value - 500
script.Parent.Parent.Visible = false
wait(2.5)
if not game.Workspace:FindFirstChild("TvClone1") then
local tvmakerclone = game.ReplicatedStorage.TvMakers.TvMakerLVL1:Clone()
tvmakerclone.Name = "TvClone1"
tvmakerclone.Parent = game.Workspace
elseif game.Workspace:FindFirstChild("TvClone1") and not
game.Workspace:FindFirstChild("TvClone2") then
local tvmakerclone = game.ReplicatedStorage.TvMakers.TvMakerLVL1:Clone()
tvmakerclone.Name = "TvClone2"
tvmakerclone.Parent = game.Workspace
end
end
Change local Cash = player:WaitForChild("leaderstats"):WaitForChild("Cash")
By that
local Leader = player:WaitForChild("leaderstats" ,5)
if leader ~= nil then
local Cash = Leader:WaitForChild("Cash" ,5)
if Cash ~= nil then
Cash.Value = Cash.Value - 500
end
end
But you should use a script for that, because in a local script, the clone will be cloned in the client side, and the cash will be changed in client side.
Everything in client side can’t do anything on the server side unless you use a remote event.
So here your cash will be not saved and if your clone need to do something in the server side, like attack mobs or other player, it will not work.
local hover = game.SoundService.HoverSound
script.Parent.MouseEnter:Connect(function()
hover:Play()
end)
local player = game.Players.LocalPlayer
local Leader = player:WaitForChild("leaderstats" ,5)
if leader ~= nil then
local Cash = Leader:WaitForChild("Cash" ,5)
if Cash ~= nil then
Cash.Value = Cash.Value - 500
end
end
local leaderstats = player.leaderstats
script.Parent.MouseButton1Click:Connect(function()
script.Parent.PurchaseScript.Disabled = true
Cash.Value = Cash.Value - 500
script.Parent.Parent.Visible = false
wait(2.5)
if not game.Workspace:FindFirstChild("TvClone1") then
local tvmakerclone = game.ReplicatedStorage.TvMakers.TvMakerLVL1:Clone()
tvmakerclone.Name = "TvClone1"
tvmakerclone.Parent = game.Workspace
elseif game.Workspace:FindFirstChild("TvClone1") and not
game.Workspace:FindFirstChild("TvClone2") then
local tvmakerclone1 = game.ReplicatedStorage.TvMakers.TvMakerLVL11:Clone()
tvmakerclone1.Name = "TvClone2"
tvmakerclone1.Parent = game.Workspace
end
end
script.Parent.MouseButton1Click:Connect(function()
local player = game.Players.LocalPlayer
local Leader = player:WaitForChild("leaderstats" ,5)
if leader ~= nil then
local Cash = Leader:WaitForChild("Cash" ,5)
if Cash ~= nil then
Cash.Value = Cash.Value - 500
end
end
script.Parent.PurchaseScript.Disabled = true
script.Parent.Parent.Visible = false
wait(2.5)
if not game.Workspace:FindFirstChild("TvClone1") then
local tvmakerclone = game.ReplicatedStorage.TvMakers.TvMakerLVL1:Clone()
tvmakerclone.Name = "TvClone1"
tvmakerclone.Parent = game.Workspace
elseif game.Workspace:FindFirstChild("TvClone1") and not
game.Workspace:FindFirstChild("TvClone2") then
local tvmakerclone1 = game.ReplicatedStorage.TvMakers.TvMakerLVL11:Clone()
tvmakerclone1.Name = "TvClone2"
tvmakerclone1.Parent = game.Workspace
end
end)