I’m trying to make it so that if you either press Q or J a banana peel appears in your current position, I’m experiencing some issues though.
local plr = game.Players.LocalPlayer
uis.InputBegan:Connect(function(keypress)
if keypress.UserInputType.EnumType == Enum.KeyCode.J or keypress.UserInputType.EnumType == Enum.KeyCode.Q then
local repli = game:GetService("ReplicatedStorage")
repli.bananaPeel:FireServer(plr)
end
end)
this is the local script
local replicatedstorage = game:GetService("ReplicatedStorage")
replicatedstorage.bananaPeel.OnServerEvent:Connect(function(player)
local plr = game.Players:GetPlayerFromCharacter(player)
local peel = storage.BananaPeel:Clone()
peel.Parent = workspace
peel.Position = plr.Character.RightLeg
end)
In the server script, put a print in the top and print the player, if anything at all prints then it’s an issue with your clone script, else it’s your key script.
As @domboss37 and @escapethepaw already said:
Whenever you call :FireServer(), the script automatically passes the player as an argument. So, when you’re doing function(player), that player already is the player. There is no need to define a plr variable, you can just do peel.Position = player.Character.RightLeg.
I fixed your scripts for you just copy and paste these in.
Server Script
local replicatedstorage = game:GetService("ReplicatedStorage")
replicatedstorage.bananaPeel.OnServerEvent:Connect(function(player,char)
local peel = game.ServerStorage:WaitForChild("BananaPeel"):Clone()
peel.Parent = workspace
peel.Position = char:WaitForChild("Right Leg").Position
end)
Local Script
local plr = game.Players.LocalPlayer
local Character = plr.Character
game:GetService("UserInputService").InputBegan:Connect(function(keypress)
if keypress.KeyCode == Enum.KeyCode.J or keypress.KeyCode == Enum.KeyCode.Q then
local repli = game:GetService("ReplicatedStorage")
repli.bananaPeel:FireServer(Character)
end
end)
Here’s a list of issues I found within your scripts:
1 In the local script you added the player in the FireServer function.
You don’t need to do this sense Roblox does this automatically.
2 You put UserInputType instead of Keycode. You wouldn’t need the type of input the users giving you sense you were only detecting if a certain key is pressed.
3 When you were setting the position of the peel you didn’t set it to the right leg’s position. When setting the position of a object to another you always need both objects positions.
There’s more I found but everyone else who contributed to this post already found them. I hope you learn from this experience and grow has a programmer!