The touch event returns a part, not a player, so you are just any part that touches the script’s parent when doing this. I would recommend doing
script.Parent.Touched:Connect(function(part)
if part.Parent:WaitForChild("Humanoid") then
local plr = Game.Players:GetPlayerFromCharacter(part.Parent.Humanoid)
event2:FireClient(plr)
wait(1)
event:FireClient(plr)
end)
This is the modified server code, it was showing an error when sending FireClient because you were not passing the player parameter, try testing this modification I made to your code, i also added a debounce to prevent the remote event from being executed multiple times when is pressed, you can modify the debounce time in this line: local DebounceTime = 2
Server:
local repStorage = game:GetService("ReplicatedStorage")
local event = repStorage.RemoteEvent
local event2 = repStorage.RemoteEvents.BlackFrame
local Debounces = {}
local DebounceTime = 2
script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if not Debounces[player] or (tick() - Debounces[player]) > DebounceTime then
Debounces[player] = tick()
event2:FireClient(player)
task.wait(1)
event:FireClient(player)
end
end
end
end)
Client:
local repStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local player = game:GetService("Players").LocalPlayer
local event = game.ReplicatedStorage.RemoteEvents.BlackFrame
local blackFrame = script.Parent.BlackFrame
local tween = tweenService:Create(blackFrame,TweenInfo.new(1),{BackgroundTransparency = 0})
local tween2 = tweenService:Create(blackFrame,TweenInfo.new(1),{BackgroundTransparency = 1})
event.OnClientEvent:Connect(function()
tween:Play()
task.wait(3)
tween2:Play()
end)
Let me know if it worked for you, and if you encounter any errors, send me a screenshot of the output to identify the issue
It was hard for me to learn :FireClient() as well. It’s important to understand the difference between the player, and their character.
Players -
Are located in the Players service
Represent the true player in the game
Characters -
Are by default located in workspace
Represent the person the player controls.
FireClient() calls for a player object, not their character.
Interactions with 3D objects can return either one depending on what you’re doing. For example, BasePart.Touched returns the part that touched (which, if a character, can be found with TouchedPart.Parent) and a ProximityPrompt returns the actual player who triggered it.
Getting the player’s character and vice versa can be pretty essential. Use game:GetService(“Players”):GetPlayerFromCharacter(character) to get player from character. Use Player.Character (if one exists) to get the player’s character.
That being said, here is what you could do server side
local TouchPart = script.Parent --set this to the part that gets touched
local RemoteEvent = game:GetService(“ReplicatedStorage”).RemoteEvent --change this to the remote event
TouchPart.Touched:Connect(function(part) --this could be any part, so we have to check that it’s from a character
if part.Parent:FindFirstChild(“Humanoid”) then --we have to make sure that whats touching has a humanoid (which could be a character)
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player then --check to make sure it’s a player
RemoteEvent:FireClient(player)
end
end
end)