Hey I made script with Event Touched, and I want when someone touch it with body it pop up Gui from StarterGui. But when I touch it it dosen’t work. I used Script (not localscript) and insert it in part.
Here is script:
local plr = game.Players.LocalPlayer
local Player = game:GetService("Players") -- Get LocalPlayer
local leaderstats = Player:WaitForChild("leaderstats") -- Get leaderstats
local teleport = script.Parent.Parent.Teleport -- Get Teleport
local buyed = plr.Islands.island1 -- Get BoolValue from FirstIsland is Buyed
local buyislandgui = plr.PlayerGui.BuyIslandGUI.IslandFrame -- Get IslandFrame from StarterGui
local cost = 500 -- Cost
local cost2 = 20 -- Cost2
local elemental = leaderstats.Dirt -- Dirt, Grass, Rock
local elemental2 = leaderstats.Grass -- Dirt, Grass, Rock
-- Function onTouched(hit)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
buyislandgui.Visible = true
end
end)
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
buyislandgui.Visible = true
end
end)
doesn’t work because there is no plr
if you really want to make the GUI visible server sided you would need to do it like
function getPlayerFromString(name)
for i,v in pairs(game.Players:GetPlayers()) do
if v.Name == name then
return v
end
end
return false
end
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local x = getPlayerFromString(hit.Parent.Name)
if x == false then error("Something went wrong.") else
local pgui = x.PlayerGui
local gui = pgui.BuyIslandGui.IslandFrame
gui.Visible = true
end
end
end)