This script that I made is supposed to tween a Frame in a GUI when you touch a brick, but I keep getting this error:
attempt to index a nil value.
This makes no sense, because the GUI is in "PlayerGui". Also this script works in studio and not in the game itself..
script.parent.Touched:Connect(function(m) local player = game.Players:GetPlayerFromCharacter(m.Parent); wait(0.1) player.PlayerGui:WaitForChild("Teleport").Frame:TweenPosition(UDim2.new(0,0,0,0), "Out", "Linear", 1) end
Any help would be appreciated.
This is because in line 1, it’s script.Parent
, not script.parent
.
You also tried to modify the GUI in the server, which is a huge no no.
You must use a RemoteEvent
and fire it to the client if they touch your block.
-- LocalScript local plr = game:GetService("Players").LocalPlayer local remote = Instance.new("RemoteEvent") remote.Name = "TweenGui" remote.Parent = game:GetService("ReplicatedStorage") remote.OnClientEvent:Connect(function() plr:WaitForChild("PlayerGui").Teleport.Frame:TweenPosition( UDim2.new(), -- your position got cut off so put it here Enum.EasingDirection.Out, -- use this instead of "Out" Enum.EasingStyle.Linear, -- here too 1 ) end)
Now for the server code:
-- ServerScript local rep = game:GetService"ReplicatedStorage" local plrs = game:GetService"Players" script.Parent.Touched:Connect(function(part) local plr = plrs:GetPlayerFromCharacter(part.Parent) if plr then rep.TweenGui:FireClient(plr) end end)