I've tried the script below, but it hasn't worked! Is anyone able to help?
script.Parent.Touched:Connect(function() local object = game.StarterGui.DeathScreen.ImageLabel object:TweenPosition(UDim2.new(0.5, 0, 0.5, 0)) end)
Tip: Don’t change GUI directly from StarterGui in scripts when you want to update it for the player, StarterGui is a template which is cloned to the player upon being loaded in
Since I assume this is a local script, use game.Players.LocalPlayer.PlayerGui
instead of StarterGui and so on, then tween the Gui in your function.
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:
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,
first in the script inside the part, type the touched event and then use GetPlayerFromCharacter
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChild("Humanoid") then -- if it's a character and has a humanoid then do local player = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent) if not player then return end -- If the player doesnt exist or it's an npc then stop game.ReplicatedStorage.RemoteEvent:FireClient(player) -- The first argument of player is required end end)
then in a localscript inside the part, you have to type the remote event OnClientEvent because you fired the client (and not the server)
local player = game.Players.LocalPlayer local playerGui = player:WaitForChild("PlayerGui") -- Type it exactly or it will error game.ReplicatedStorage.RemoteEvent.OnClientEvent:Connect(function() -- We don't get the player argument if playerGui:FindFirstChild("DeathScreen") then local object = PlayerGui.DeathScreen.ImageLabel object:TweenPosition(UDim2.new(0.5, 0, 0.5, 0)) end end)