How do i make this script work with textbuttons?

I have this script that works perfectly with proximity prompt but when i change it to work with textbuttons it doesn’t work, no errors in output (script is localscript inside textbutton)
Here is the proximityprompt script that works:

local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local Modules = ServerScriptService:WaitForChild("Modules")
local Engine = require(Modules:WaitForChild("Engine"))


proximity.TriggerEnded:Connect(function(player)	
	local Character = player.Character or player.CharacterAdded:Wait()
	if not ServerStorage:FindFirstChild("Characters") then return end
	local CharacterExample = ServerStorage.Characters.CharacterExample 
	if not CharacterExample then return end
	if Character and not Engine:IsZombie(player) and not Engine:IsImmune(player) then
		Engine:Zombiefy(player, CharacterExample)
	end
end)

and here is the textbutton script that doesn’t work:

local button = script.Parent
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local Modules = ServerScriptService:WaitForChild("Modules")
local Engine = require(Modules:WaitForChild("Engine"))


local function onButtonActivated(player)
	local Character = player.Character or player.CharacterAdded:Wait()
	if not ServerStorage:FindFirstChild("Characters") then return end
	local CharacterExample = ServerStorage.Characters.CharacterExample 
	if not CharacterExample then return end
	if Character and not Engine:IsZombie(player) and not Engine:IsImmune(player) then
		Engine:Zombiefy(player, CharacterExample)
	end
end
button.Activated:Connect(onButtonActivated)

Any solutions?

1 Like

you can’t access serverstorage with a localscript

Is there any ways to access it through localscript?

you’d have to use a remoteevent or just make it a server script

I’ve decided to go with remote events and here is my current (serverscript)

local RemoteEvent = Instance.new("RemoteEvent")
local ServerScriptService = game:GetService("ServerScriptService")
local ServerStorage = game:GetService("ServerStorage")
local Modules = ServerScriptService:WaitForChild("Modules")
local Engine = require(Modules:WaitForChild("Engine"))
RemoteEvent.Parent = game.ReplicatedStorage

RemoteEvent.OnServerEvent:Connect(function(player)
	local Character = player.Character or player.CharacterAdded:Wait()
	if not ServerStorage:FindFirstChild("Characters") then return end
	local CharacterExample = ServerStorage.Characters.CharacterExample 
	if not CharacterExample then return end
	if Character and not Engine:IsZombie(player) and not Engine:IsImmune(player) then
		Engine:Zombiefy(player, CharacterExample)
	end
end)

but it still wouldn’t work

what part doesn’t work
try printing something in line 9

Nevermind it perfectly works turns out something was wrong with the textbutton, thanks!

1 Like