Here I have a drink, that could be placed down anywhere. It has a feature of remembering its state of being opened.
The state of being opened or not is also saved throughout the process of the scripts. The problem is the prop version of the drink cannot send the bool to the cloned original drink.
First, player has the original drink. Once opened, bool value sets to true, which IsOpened = true. Then, placing it down will have a fake version of the drink to be placed down. With a click detector and the saved bool value IsOpened from the original drink. Finally, my problem occurs here, where the prop version’s saved bool value did not get transferred over to a brand new cloned drink parented back to the player.
I’ve tried attributes, an alternative to bool value, did not work!
Name of the drink: Canned Water
Prop’s script:
local Tool = game:GetService("ServerStorage")["Important Gears"]:WaitForChild("Canned Water")
local State = script.Parent.Opened.Value
script.Parent.ClickDetector.MouseClick:Connect(function(player)
local NewTool = Tool:clone()
NewTool.Parent = player.Character
NewTool.IsOpened.Value = State
print(State)
print(NewTool.IsOpened.Value)
NewTool:SetAttribute("IsOpened", State)
print(player.Name .. "Picked up the drink!!")
local soundTable = {
17297659592,
}
local randomIndex = math.random(1, #soundTable)
local randomSoundId = soundTable[randomIndex]
NewTool.Handle.Place.SoundId = "rbxassetid://" .. randomSoundId
NewTool.Handle.Place:play()
if State then
print("its opened")
NewTool.Main.Enabled = true
NewTool.Opener:Destroy()
else
NewTool.Opener.Enabled = true
NewTool.Main.Enabled = false
print("its NOT opened")
end
script.Parent:Destroy()
end)
If any of you got an idea how I could fix this, hit me up please and thank you.
Okay so local State = script.Parent.Opened.Value is above all of your code correct? So whatever it was at that point of time is what State is set to
local Tool = game:GetService("ServerStorage")["Important Gears"]:WaitForChild("Canned Water")
local State = script.Parent.Opened.Value --/!!/ State value is set here
script.Parent.ClickDetector.MouseClick:Connect(function(player)
local NewTool = Tool:clone()
NewTool.Parent = player.Character
NewTool.IsOpened.Value = State --/!!/ Always setting the Value to State defined above the function.
--/!!/ So whatever State was set to above is what the value will always be.
print(State)
print(NewTool.IsOpened.Value)
What you probably want is this
local Tool = game:GetService("ServerStorage")["Important Gears"]:WaitForChild("Canned Water")
script.Parent.ClickDetector.MouseClick:Connect(function(player)
local NewTool = Tool:clone()
NewTool.Parent = player.Character
NewTool.IsOpened.Value = script.Parent.Opened.Value
print(State)
print(NewTool.IsOpened.Value)
NewTool:SetAttribute("IsOpened", State)
print(player.Name .. "Picked up the drink!!")
local soundTable = {
17297659592,
}
local randomIndex = math.random(1, #soundTable)
local randomSoundId = soundTable[randomIndex]
NewTool.Handle.Place.SoundId = "rbxassetid://" .. randomSoundId
NewTool.Handle.Place:play()
if State then
print("its opened")
NewTool.Main.Enabled = true
NewTool.Opener:Destroy()
else
NewTool.Opener.Enabled = true
NewTool.Main.Enabled = false
print("its NOT opened")
end
script.Parent:Destroy()
end)