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

How Do I Make A Part Apear Under A Player When A Key Is Pressed ?

Asked by
Split_s 21
3 years ago

So I'm Trying To Make A Horror Game , And I Want To Allow The Player To Drop Glowsticks On The Ground When They Press A Key . I Tried Multiple Methods But None Of Them Seem To Work Out For Me And Since I Am Not That Experienced With Scripting I'm Unable To Create One Myself , That's Why I Decided To Request Some Help Here . I Hope Someone Can Solve My Problem !

Thank You.

2 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

If you have the glowstick in the ServerStorage, you actually need two scripts and a remote,

Create a remote called 'Glowstick' in ReplicatedStorage and the glowstick named 'Glowstick' in ServerStorage

LocalScript in starter gear

local remote = game.ReplicatedStorage:WaitForChild('Glowstick')
local uis = game:GetService('UserInputService')

uis.InputBegan:Connect(function(input, typing)
if (input.KeyCode == Enum.KeyCode.A) and (not typing) then 
remote:FireServer()
end

end)

Script above basically fires the remote if player clicks button 'A' and is not typing (chat etc.)

The second script in ServerScriptService

local remote = game.ReplicatedStorage:WaitForChild('Glowstick')

remote.OnServerEvent:Connect(function(plr)
local glowstick = game.ServerStorage:FindFirstChild('Glowstick')

local chr = plr.Character

local glow = glowstick:Clone()

local hrp = chr:FindFirstChild('HumanoidRootPart')

glow.Parent = workspace

glow.Position = hrp.Position + hrp.CFrame.LookVector + Vector3.new(1,0,0)


end)

This spawns the glowstick infront of player torso (will fall down if not anchored)

Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

you can do this by creating a local script in starter pack.

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()


Mouse.KeyDown:Connect(function(Key)
Key = Key:lower()
if Key == 'b' then
local gs = game.ServerStorage.Glowstick:Clone()
gs.Parent = workspace
gs.Part1.Position = Player.RightFoot.Position
gs.Part2.Position = Player.RightFoot.Position
gs.Part1.Anchored = true
gs.Part2.Anchored = true

wait(5)

gs:Destroy()

end
end)

remove the wait(5) and gs:Destroy() if you want it to stay forever. make sure to setup your glowstick the same way it is in the script, and add parts to the script if there's more. make sure ur glowstick is named Glowstick and is in server storage should work u might need to add a few ends

0
You can't access ServerStorage from Client Charmander_fan666 30 — 3y

Answer this question