Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

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

1 comment

0

You can't access ServerStorage from Client

This discussion is preserved as it was. New answers, comments, and votes are closed.