Answered by
4 years ago Edited 4 years ago
Touched events on the client is not a good thing and localscripts don't work in the workspace, inside a part etc., you can use a remote event and fire it to the client to tween it for the player who touched it, assuming you already know remote events, if you don't then here:
Remote Events and Functions
put the remote event in ReplicatedStorage, you also to use GetPlayerFromCharacter which will get the player from character, if its an npc tho, it will be nil,
GetPlayerFromCharacter
first in the script inside the part, type the touched event and then use GetPlayerFromCharacter
1 | script.Parent.Touched:Connect( function (hit) |
2 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
3 | local player = game:GetService( "Players" ):GetPlayerFromCharacter(hit.Parent) |
4 | if not player then return end |
5 | game.ReplicatedStorage.RemoteEvent:FireClient(player) |
then in a localscript inside the part, you have to type the remote event OnClientEvent because you fired the client (and not the server)
1 | local player = game.Players.LocalPlayer |
2 | local playerGui = player:WaitForChild( "PlayerGui" ) |
4 | game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect( function () |
5 | if playerGui:FindFirstChild( "DeathScreen" ) then |
6 | local object = PlayerGui.DeathScreen.ImageLabel |
7 | object:TweenPosition(UDim 2. new( 0.5 , 0 , 0.5 , 0 )) |