I have a part that is in Server Storage.
I want to script it to get cloned in front of the player when the player presses 'E'
I also want it to get destroyed when the player clicks on it.
How do I go about this?
I have a part that is in Server Storage.
I want to script it to get cloned in front of the player when the player presses 'E'
I also want it to get destroyed when the player clicks on it.
How do I go about this?
Easy. Here is what I would do.
local ClonePart = game.ServerStorage.ClonePart
local Player = game.Players.LocalPlayer
local Character = Player.Character
local UIS = game:GetService("UserInputService")
UIS.InputBegan:connect(function(key)
partIn = false
if key.KeyCode = Enum.KeyCode.E and partIn == false then
partIn = true
newClone = ClonePart:Clone()
newClone.Parent = game.Workspace
neClone.CFrame = Character.HumanoidRootPart.CFrame + CFrame.new(0,0,5)
clickDetector = Instance.new("ClickDetector")
clickDetector.Parent = newClone
if clickDetector.Clicked == true and partIn == true then
newClone:Destroy()
partIn = false
end
end
end)
Ok, first off, ClonePart will be the part in ServerStorage, whatever the name of it would be. Player is obvious, any scripter will be familiar with the second line. The UIS I put in is a variable for the UserInputService, which can detect User Input, obviously. Then the function will run if any input is sensed, which has the title "key", which can be changed to any name. Then a variable called partIn is set to false. This variable will prevent a user from repeatidly cloning the part in. Then the If statement detects if the user presses "e" and if partIn == false. It then clones the part and makes it's parent the Workspace, it also makes it's CFrame the character's plus 5 in the z Axis. A click detector is also added in the part to be able to detect if you press the part, and it is parented to newClone. Then the next If Statement checks if you have clicked the part and partIn == true. it then destroys the part and makes partIn = false. I might have messed up on this script. Wow, lol, I just wrote that from the top of my head, lol. Again, I mite hav hadz de gramer orr sintax eror(lol).
Thanks so much!!!! Going to try this out and report back!
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
Not a request site -
-______- I cant ask for help on script that would be cool to implement in different kinds of games?
I don't think scripts can access the ServerStorage, so you would probably have to use a RemoteEvent to do so, and research on the UserInputService, and you can use the .Touched event for when the player clicks it.