Problem:
local String = Instance.new("ObjectValue", game.Workspace.Cake:FindFirstChild("Batter")) String.Value = plr String.Name = "Player Who Owns the Part"
Creates a string but puts it into the same part every time a part is made, and not the newest part.
Full Code:
local Button = script.Parent.Button2 local Drop = script.Parent.Drop local Ready = true local plrValue; function MakeBlock(plr) -- added plr, because first argument of mouseclick is the player who has clicked it if Ready then Ready = false local Block = Instance.new("Part", game.Workspace.Cake) Block.CFrame = Drop.CFrame Block.Size = Vector3.new(3, 1.2, 3) Block.Material = Enum.Material.SmoothPlastic Block.BrickColor = BrickColor.new("Pastel brown") Block.Name = "Batter" local String = Instance.new("ObjectValue", game.Workspace.Cake:FindFirstChild("Batter")) String.Value = plr String.Name = "Player Who Owns the Part" game.Debris:AddItem(Block, 400) wait(3) Ready = true end end Button.ClickDetector.MouseClick:Connect(MakeBlock)
Everything works, I just need it to insert a String into the newest part of the group..
This script listens to a button that tells the script to make a new part called Batter, in a group named Cake.
Then it gives the Batter a Object Value which states the owner.
It keeps placing the string into the same part though.. Here's whats happening. I need to find a way to make it put a string in the newest part
If anyone can help, that would be great. :)
Just set the object's parent to Block instead of :FindFirstChild("Batter")
FindFirstChild does what it says - it finds the first child that matches the name. The newest batter won't be the first child.
local Button = script.Parent.Button2 local Drop = script.Parent.Drop local Ready = true local plrValue; function MakeBlock(plr) -- added plr, because first argument of mouseclick is the player who has clicked it if Ready then Ready = false local Block = Instance.new("Part", game.Workspace.Cake) Block.CFrame = Drop.CFrame Block.Size = Vector3.new(3, 1.2, 3) Block.Material = Enum.Material.SmoothPlastic Block.BrickColor = BrickColor.new("Pastel brown") Block.Name = "Batter" local String = Instance.new("ObjectValue") String.Parent = Block String.Value = plr String.Name = "Player Who Owns the Part" game.Debris:AddItem(Block, 400) wait(3) Ready = true end end Button.ClickDetector.MouseClick:Connect(MakeBlock)
local Button = script.Parent.Button2 local Drop = script.Parent.Drop local Ready = true local plrValue; local newBatter; function MakeBlock(plr) -- added plr, because first argument of mouseclick is the player who has clicked it if Ready then Ready = false newBatter = Instance.new("Part", game.Workspace.Cake) Block.CFrame = Drop.CFrame Block.Size = Vector3.new(3, 1.2, 3) Block.Material = Enum.Material.SmoothPlastic Block.BrickColor = BrickColor.new("Pastel brown") Block.Name = "Batter" local String = Instance.new("ObjectValue", newBatter) String.Value = plr String.Name = "Player Who Owns the Part" game.Debris:AddItem(Block, 400) wait(3) Ready = true end end Button.ClickDetector.MouseClick:Connect(MakeBlock)
so i modified to code so that it will do what you wanted, basically i constantly keep a reference to the last created batter and give that the string, sintead of look for the firstchild named batter
You should use @EmeraldLimes 's module Attributez rather than creating an ObjectValue
Thank's for the replies guys.
All your suggestions look like they'll work. :)