I can't change buttongui.visible = true

i have localscript in playergui after run will place inside PlayerGui but after use skill from keyboard or button activatedButton.Visible = true will change and return to false but if it outside InputBegan will can use


Captfhfhure

local ScreenGui = script.Parent
local activatedButton = ScreenGui:WaitForChild("Activated")  -- Wait for 'Activated' frame
local unactivatedButton = ScreenGui:WaitForChild("Unactivated")  -- Wait for 'Unactivated' frame
local CollectionService = game:GetService("CollectionService")
local MODEL_TAG = "TagPropSkill"        -- แท็กเฉพาะสำหรับโมเดลของคุณ
local activePrompts = {}               -- ตารางเพื่อติดตามพรอมต์ที่ใช้งานอยู่
local UIS = game:GetService("UserInputService")
local connectionTouch
local connectionKey
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ActivateSkillPossessed = ReplicatedStorage.ActivedSkillPossessed:WaitForChild("ActivateSkillPossessedEvent")
local UICancleSkillPossessed = ReplicatedStorage.ActivedSkillPossessed:WaitForChild("UICancleSkillEvent")

UICancleSkillPossessed.OnClientEvent:Connect(function()
	print('work')
	activatedButton.Visible = true
end)

local function handleProximity(model)
	local proximityPrompt = model.Head:WaitForChild("ProximityskillPossessed")
	local highlight = model.Head:WaitForChild("Highlight")

	activePrompts[proximityPrompt] = true 

	proximityPrompt.PromptShown:Connect(function(player)
		if activePrompts[proximityPrompt]then
			unactivatedButton.Visible = true
			highlight.Enabled = true
			connectionTouch = unactivatedButton.InputBegan:Connect(function(press)
				if press.UserInputType == Enum.UserInputType.MouseButton1
					or press.UserInputType == Enum.UserInputType.Touch
				then
					ActivateSkillPossessed:FireServer(model)
					activePrompts[proximityPrompt] = nil
					activatedButton.Visible = true
					connectionTouch:Disconnect()  
					connectionKey:Disconnect()
				end
			end)
			connectionKey = UIS.InputBegan:Connect(function(press)
				if press.KeyCode == Enum.KeyCode.E 
					or press.KeyCode == Enum.KeyCode.ButtonX
				then
					print('1')
					ActivateSkillPossessed:FireServer(model)
					activePrompts[proximityPrompt] = nil
					activatedButton.Visible = true
					unactivatedButton.Name = '14698486'
					connectionTouch:Disconnect()  
					connectionKey:Disconnect()
				end
			end)
		end
	end)

	proximityPrompt.PromptHidden:Connect(function(player)
		unactivatedButton.Visible = false
		highlight.Enabled = false
		connectionTouch:Disconnect()
		connectionKey:Disconnect()
	end)
end

for _, model in ipairs(CollectionService:GetTagged(MODEL_TAG)) do
	print(model)
	handleProximity(model)
end

CollectionService:GetInstanceAddedSignal(MODEL_TAG):Connect(handleProximity)

1 Like

Sorry, can you explain better what are u trying to achive?

I just want to show Button Activated after pressing E or clicking on Button unActivated. But after the conditions are met, Button Activated changes to true for a short time. and change back to False like in the clip in the range 0.01 - 0.03 , but I don’t know why the problem occurred.

hmm… i dont know if this is the problem but i think if you hide the prompt or something, this function would fire and hide the button?

2 Likes

This is a check from the Proximity Prompt to see if a player has come within range of the skill. But I think the problem is on the server side because the model was changed causing the data in the Players to be completely reset, causing the problem.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local FolderReplicated = Instance.new("Folder", ReplicatedStorage)
FolderReplicated.Name = "ActivedSkillPossessed"
local CollectionService = game:GetService("CollectionService")
local ActivateSkillPossessedEvent = Instance.new("RemoteEvent", FolderReplicated)
ActivateSkillPossessedEvent.Name = "ActivateSkillPossessedEvent"

local function UseSkillPossessed(plr,Model)
	local characterClone = Model:Clone()
	local originalCharacter = plr.Character
	originalCharacter.Archivable = true -- Make the character temporarily archivable
	local playerClone = originalCharacter:Clone()
	originalCharacter.Archivable = false -- Set it back to false
	playerClone.Name = plr.Name .. "_Clone"
	
	local Proximity = characterClone.Head:FindFirstChild('ProximityskillPossessed') 
	if Proximity then 
		Proximity:Destroy() 
	end
	characterClone.Name = plr.Name
	plr.Character = characterClone
	characterClone.Parent = workspace
	
	CollectionService:RemoveTag(characterClone, 'TagPropSkill')
	local playerFolder = ReplicatedStorage.ActivedSkillPossessed:FindFirstChild(plr.Name)
	if not playerFolder then
		playerFolder = Instance.new("Folder")
		playerFolder.Name = plr.Name
		playerFolder.Parent = ReplicatedStorage
	end
	
	playerClone.Parent = playerFolder
	Model.Parent = playerFolder
	
end

ActivateSkillPossessedEvent.OnServerEvent:Connect(UseSkillPossessed)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.