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

Help on trying to make make a simple script that puts a brick in and out of SerevrStorage?

Asked by 9 years ago
Detect=workspace.Part.ClickDetector
Brick=workspace.Part

function putBrickValueInInventory(player)
game.StarterGui.ScreenGui.TextLabel.BackgroundColor3=Color3.new(255, 255, 255)
local Brick2=Brick:Clone()
Brick2.Parent=game.ServerStorage
Brick:remove()  
end

function Lol()
local BackIG=game.ServerStorage.Part:Clone()
BackIG.Parent=game.Workspace
local PP=game.Players.Player.Character.Torso.CFrame
BackIG.Position=Vector3.new(PP)
end

Detect.MouseClick:connect(putBrickValueInInventory)
game.StarterGui.ScreenGui.TextButton.MouseButton1Click:connect(Lol)

It works up to when I click the brick, it clones the brick into the ServerStorage, but the color of the TextButton in the Gui, doesn't change color. Also, when I click the button, it doesnt put the brick back into the workspace. Help please?

0
You mean like if the brick is already in workspace? EzraNehemiah_TF2 3552 — 9y

1 answer

Log in to vote
2
Answered by 9 years ago

First, there are a lot of problems.


Detect isn't needed because when the Brick is cloned all the children in the brick. Children are objects inside of the brick in the family tree. We need detect for the event, but we could do Brick.ClickDetecter.MouseClick instead.


Now about Color3. Color3 doesn't go up to 255. The only numbers that you can have in a Color3 Value is 1 or 0. To get a number like 135, you need to do this. Color3.new(135/255,135/255,135/255). 1 is the same as 255 and 0 is the same as 0.


Another problem is the "PP". What are the chances of a person named "Player" going to join the game? Instead do something like this to choose a random player maybe: game.Players:GetChildren()[math.random(1, #game.Players:GetChildren())]. If this were a local script you could use local player. But in this case, since function "lol" is a text button you can't actually get the player from there.


Another problem is the variable PP. Since the variable is a property not an actual value, you need to do this instead. PP=game.Players.Player.Character.Torso BackIG.Position=PP.Position

Brick=workspace.Part

function putBrickValueInInventory(player)
game.StarterGui.ScreenGui.TextLabel.BackgroundColor3=Color3.new(1,1,1) --Same as 255,255,255
local Brick2=Brick:Clone()
Brick2.Parent=game.ServerStorage
Brick:Destroy() --Remove doesn't get rid of the brick. If you do Brick.Parent = workspace after Brick:remove() it will still come back.  
end

function Lol()
local BackIG=game.ServerStorage.Part:Clone()
BackIG.Parent=game.Workspace
local PP=game.Players.Player.Character.Torso.CFrame
BackIG.Position=PP.Position
end

Brick.ClickDetector.MouseClick:connect(putBrickValueInInventory)
game.StarterGui.ScreenGui.TextButton.MouseButton1Click:connect(Lol)


EDIT

Well, if you want the brick to disappear if the brick is already in:

Brick=workspace.Part

function putBrickValueInInventory(player)
game.StarterGui.ScreenGui.TextLabel.BackgroundColor3=Color3.new(1,1,1) --Same as 255,255,255
local Brick2=Brick:Clone()
Brick2.Parent=game.ServerStorage
Brick:Destroy() --Remove doesn't get rid of the brick. If you do Brick.Parent = workspace after Brick:remove() it will still come back.  
end

function Lol()
local BackIG=game.ServerStorage.Part:Clone()
if not workspace.Part then
BackIG.Parent=game.Workspace
local PP=game.Players.Player.Character.Torso.CFrame
BackIG.Position=PP.Position
else
workspace.Part:Destroy()
end
end

Brick.ClickDetector.MouseClick:connect(putBrickValueInInventory)
game.StarterGui.ScreenGui.TextButton.MouseButton1Click:connect(Lol)

Do some variation of this. Because what are the chances of a part named "Part" and the name is Completely different from other parts names.

0
+1 for good answer Mystdar 352 — 9y
0
Thanks EzraNehemiah_TF2 3552 — 9y
0
How would I amke it so, if any player clickss the brick, it would go into the serever storage? XrxShadowxX 0 — 9y
Ad

Answer this question