I have this situation where I have a part that is being created on the server-side when any player press Shift. And I am handling the effects on the Client-side. The effects on the Client-side will be triggered when the player or something touches the part. Then after 10seconds, the parts get destroyed.
The problem is the part is inserted but on the Client-side the touch event is not registering because the part is only there temporally so the event can’t just be fixed.
How can I go about making this work and having the part being created on the server while I handle the effects on the Client?
Code:
--Local script
local RS = game:GetService("ReplicatedStorage")
local UIS = game:GetService("UserInputService")
local test = RS:WaitForChild("RE_Test")
UIS.InputBegan:connect(function(inst)
if inst.KeyCode == Enum.KeyCode.LeftShift then
test:FireServer()
--Handling effects on client
local partToDetect = game.Workspace:FindFirstChild("Part")
if partToDetect ~= nil then
print("Detecting")
partToDetect.Touched:Connect(function(touched)
partToDetect.BrickColor.random()
end)
end
end
end)
--Server Script
local RS = game:GetService("ReplicatedStorage")
local createPartEvent = RS:WaitForChild("RE_Test")
local function onCreatePartFired(player)
print("Fierd Server")
--Creating Part Securly On server
local part = Instance.new("Part")
part.Parent = game.Workspace
wait(10)
part:Destroy()
end
createPartEvent.OnServerEvent:Connect(onCreatePartFired)
LocalEffect.rbxl (22.0 KB)