Hey! I’m a new person to coding and I want to make a item that places blocks but after 2 seconds of being in workspace, they self destruct I already have the place block script thanks to one of my friends explaining a code, but I need to know how to make the block destruct itself after being in workspace for 2 seconds. Please help me out, here is the script. Thank you for your time!
function place()
p = Instance.new(“Part”)
p.Parent = game.Workspace
p.Name = game.Players.LocalPlayer.Name
p.BrickColor = game.Players.LocalPlayer.PlayerGui.Vectors.Color.Value
if game.Players.LocalPlayer.PlayerGui.Vectors.Anchor.Value == 1 then
p.Anchored = true
elseif game.Players.LocalPlayer.PlayerGui.Vectors.Anchor.Value == 0 then
p.Anchored = false
end
p.Size = game.Players.LocalPlayer.PlayerGui.Vectors.VValue.Value
p.Position = game.Players.LocalPlayer.Character.Humanoid.TargetPoint
end
Heyo, welcome to the world of scripting! After waiting for 2 seconds by using wait(2) or task.wait(2), you can then destroy the p instance (Which would be your part)
There is also a couple things to note in relation with your script, if you wouldn’t mind me going through all of them
Most of these lines won’t be able to be accessed because you’re attemping to obtain a LocalPlayer variable, which can only be used inside LocalScripts (If this already is one, do consider adding variables to make it easier to reference what you’re exactly changing )
local Tool = script.Parent --Is this a tool?
local function Place()
local Char = Tool.Parent
local Plr = game.Players:GetPlayerFromCharacter(Char)
if Char and Plr then
local Humanoid = Char:WaitForChild("Humanoid")
local PlayerGui = Plr:WaitForChild("PlayerGui")
local Vectors = PlayerGui:WaitForChild("Vectors")
local P = Instance.new("Part")
P.Name = Char.Name
P.BrickColor = Vectors.Color.Value
if Vectors.Anchor.Value == 1 then
P.Anchored = true
elseif Vectors.Anchor.Value == 0 then
P.Anchored = false
end
P.Size = Vectors.VValue.Value
P.Position = Humanoid.TargetPoint
wait(2)
P:Destroy()
end
end
Tool.Activated:Connect(Place)
Thanks for going out of your way and helping me out! But sadly the script doesn’t work… I don’t think its compatible with one of my GUI activations script.
Hm, would it be possible to check out your Gui Scripts that changes the Values of your Value Objects? And might I ask what type it is? (Script/LocalScript/ModuleScript)
So there is actually a difference with changing Value Objects in the client & the server
They work differently, but if you attempt to value a Value Object (NumberValue, IntValue, StringValue, etc) from the client, it will not replicate towards the server because only the client can see what’s changed from this side (I believe this is set up due to hackers from preventing to exploit replication)
What we can probably use, is something that’s called a RemoteEvent & this object can be very handy for handling one-way transportations from the client-server/server-client
What we’ll use, are 2 functions/events that this RemoteEvent has:
FireServer() would fire a event from the client, to the server (This can only be used in LocalScripts)
OnServerEvent would detect & recieve those said “events” from the client side (This can only be used in Scripts)
But from what you sent me, I don’t really see any .Value changes you’re making Could you send a LocalScript that changes the Values inside your PlayerGui?