Note: I know the event Touched
exist, but it seems to not work this time.
I made a LocalScript
that has a function that triggered whenever a player presses the letter 'R'. When it got triggered, it'll fire a RemoteEvent
to the server and the ServerScript
will create a Part
and made it anchored, CanCollide
to false and positioned to a little front of the character,
Then, I want it to see if there's a Part
that touched it but it didn't work and I understand why. I just don't know how to fix or find an alternative way. I can't really phrase the problem I'm facing right now so I'm very sorry.
If you're curious, this is the inside of the LocalScript
local userinputservice = game:GetService("UserInputService") local keypressre = game:GetService("ReplicatedStorage"):WaitForChild("KeyPress") userinputservice.InputBegan:Connect(function(input, gameprocessed) if input.UserInputType == Enum.UserInputType.Keyboard then if input.KeyCode == Enum.KeyCode.R then keypressre:FireServer("R") end end end)
This is the ServerScript
one.
local keypressre = game:GetService("ReplicatedStorage"):WaitForChild("KeyPress") keypressre.OnServerEvent:Connect(function(player, input) if input == "R" then print("Interact!") local touch = Instance.new("Part") local playervalue = Instance.new("ObjectValue",touch) playervalue.Name = "Player" playervalue.Value = player touch.Name = "TOUCH" touch.Anchored = true touch.CanCollide = false touch.Size = Vector3.new(2,4,2) touch.Parent = workspace touch.CFrame = player.Character.HumanoidRootPart.CFrame:ToWorldSpace(CFrame.new(0,0,-3)) touch.Touched:Connect(function(part) if part:IsA("BasePart") then print("debugtest") end end) wait(.2) touch:Destroy() end end)
Any help or advice is welcome.