I have 5 question in my code im new dev for make game

This is my code. Each code in the model is slightly different but the logic is the same. and my code run on server

Object : vase

local SkillPossessed = script.Parent.SkillPossessed
local plr = game.Players.LocalPlayer
local Part = script.Parent
local Players = game:GetService("Players")
local UIS = game:GetService("UserInputService")
local function UseSkillPossessed(plr,Use)
	local Data = {Name = 'SkillPossessed'}
	print(plr.Name .. " UseSkillPossessed")
	local Character = plr.Character or plr.CharacterAdded:Wait()
	local Humanoid = Character:WaitForChild("Humanoid")
	local HumanoidDescription = Humanoid:GetAppliedDescription()
	local humanoidDescriptionFromUser = Players:GetHumanoidDescriptionFromUserId(plr.userId)
	local weld = Part.WeldConstraint

	if Character and Character:IsA("Model") then
		for _, part in ipairs(Character:GetDescendants()) do
			if part:IsA("Accessory") then
				local handle = part:FindFirstChild("Handle")
				if handle and handle:IsA("BasePart") then
					if Use == true then
						--handle.Transparency = 1
						handle.Transparency = 1
					elseif Use == false then
						--handle.Transparency = 0.7
						handle.Transparency = 0.7
					end
				end
			elseif part:IsA("MeshPart") and part.Name ~= "Handle" then
				if Use == true then
					--part.Transparency = 1
					part.Transparency = 1
				elseif Use == false then
					--part.Transparency = 0.7
					part.Transparency = 0.7
				end
				if part.Name == "Head" then
					--part.Transparency = 1
					part.face.Transparency= 1
					part.Transparency = 1
				end
			end
		end
	end
	if Use == false then
		HumanoidDescription.DepthScale = 1
		HumanoidDescription.HeadScale = 1
		HumanoidDescription.HeightScale = 1
		HumanoidDescription.WidthScale = 1

		weld.Part0 = nil
		weld.Part1 = nil 

		SkillPossessed.ActionText = "Possessed Object"
		SkillPossessed.MaxActivationDistance = 25
		SkillPossessed.Exclusivity = 1
		SkillPossessed.RequiresLineOfSight = true

		Part.Position = Part.Position + Vector3.new(2,0, 0)

	elseif Use == true then
		print('work')
		HumanoidDescription.DepthScale = 1.3
		HumanoidDescription.HeadScale = 1.3
		HumanoidDescription.HeightScale = 1.3
		HumanoidDescription.WidthScale = 1.3

		Character:WaitForChild("HumanoidRootPart").Position = Part.Position - Vector3.new(0,-2.5, 0)
		weld.Part0 = Part
		weld.Part1 = Character:WaitForChild("HumanoidRootPart")
		

		SkillPossessed.ActionText = "Leave Object"
		SkillPossessed.MaxActivationDistance = 4
		SkillPossessed.Exclusivity = 2
		SkillPossessed.RequiresLineOfSight = false
	end
	--ไม่หายตัว

	Humanoid:ApplyDescription(HumanoidDescription)
	Part.Highlight.Enabled = true
	wait(0.1)
	Part.Highlight.Enabled = false
	wait(0.1)
	Part.Highlight.Enabled = true
	wait(0.1)
	Part.Highlight.Enabled = false
	wait(0.1)
	Part.Highlight.Enabled = true
	wait(0.1)
	Part.Highlight.Enabled = false
end

local Use = false

SkillPossessed.Triggered:Connect(function(plr)
	if Use == false then
		Use = true
		UseSkillPossessed(plr,Use)
	elseif Use == true then
		Use = false
		UseSkillPossessed(plr,Use)
	end
end)

bug 1

bug 2

  1. bug 1 i have problem player not invisible , Sometimes I think it’s because of parallell that sometimes the code that makes the player invisible is completed first. But the code that shows the player’s identity was done later causing this problem. But I’m not sure whether it is or not.

  2. bug 2 i think because like bug 1 but i dont know if Do I have to cool down the skill or not?

3.Is this code effective for doing this? Or can the code be better?

4.What can be done in the client and reduce server load?

5.this not question script but My vase model has tri 1088. I don’t know if it’s too much or not. This model is just one part of the map.

im not good in english some time i use translate
ty for answer

2 Likes

Are the scripts local or normal ones?

2 Likes

this code Normal it work on server

Is there a local script that when you possessed an object it sends an event to the server? Show me your properties and the output when you go into an object. I just need a little more info.

i dont have local script for possessed object just run on workspace and use script

	elseif Use == true then
		print('work')
		HumanoidDescription.DepthScale = 1.3
		HumanoidDescription.HeadScale = 1.3
		HumanoidDescription.HeightScale = 1.3
		HumanoidDescription.WidthScale = 1.3
		
		--ถ้าต้องการ rotate
		--Part.Orientation = Vector3.new(0,0, 0)
		--Part.Orientation = Character:WaitForChild("HumanoidRootPart").Orientation

		Character:WaitForChild("HumanoidRootPart").Position = Part.Position - Vector3.new(0,-2.5, 0)
		weld.Part0 = Part
		weld.Part1 = Character:WaitForChild("HumanoidRootPart")
		

		SkillPossessed.ActionText = "Leave Object"
		SkillPossessed.MaxActivationDistance = 4
		SkillPossessed.Exclusivity = 2
		SkillPossessed.RequiresLineOfSight = false
	end

	Humanoid:ApplyDescription(HumanoidDescription)
	Part.Highlight.Enabled = true
	wait(0.1)
	Part.Highlight.Enabled = false
	wait(0.1)
	Part.Highlight.Enabled = true
	wait(0.1)
	Part.Highlight.Enabled = false
	wait(0.1)
	Part.Highlight.Enabled = true
	wait(0.1)
	Part.Highlight.Enabled = false

Capturess

this workflow will use Humanoid:GetAppliedDescription() set size character because bug if Objects bigger than character and will move position character = Object and Link Object connect Character

You might need to have a debounce or cooldown.

local debounce = false
ProximityPrompt.Triggered:Connect(function(player)
if debounce == false then
debounce = true
--code here
--after code is done do
debounce = false
end
end)

Thank you for the answer. sorry for replying late When I checked all the code again, I found a problem that I should check Debounce from the Client and send it to the server. So it takes time to edit all the code.

--Clinet
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ActivateSkillPossessed = ReplicatedStorage:WaitForChild("ActivateSkillPossessedEvent")
local plr = game.Players.LocalPlayer
local Use = false
local PossessedPart = nil
local NewPart = nil
local DataProperties = nil
local function UseSkillPossessed(plr, Use, NewPartName)
	if not PossessedPart then
		PossessedPart = NewPartName
		NewPart = NewPartName
	elseif PossessedPart == NewPartName then
		NewPart = NewPartName
	elseif PossessedPart ~= NewPartName then
		task.wait(0.1)
		NewPart = NewPartName
	end
	print(PossessedPart,'AND',NewPartName)

	DataProperties = {
		Name = 'SkillPossessed',
		Use = Use,
		PossessedPart = PossessedPart,
		NewPart = NewPart
	}
	ActivateSkillPossessed:FireServer(DataProperties) -- Send Use state to server
	PossessedPart = NewPartName
	NewPart = nil
end

ActivateSkillPossessed.OnClientEvent:Connect(function(Data)
	local NewPartName = Data.PartName
	print(DataProperties)
	if not PossessedPart or PossessedPart == NewPartName then
		if Use == false then
			Use = true
			UseSkillPossessed(plr, Use,NewPartName)
		elseif Use == true then
			Use = false
			UseSkillPossessed(plr, Use,NewPartName)
		end
	elseif NewPartName ~= PossessedPart then
		Use = true
		UseSkillPossessed(plr, Use,NewPartName)
	end
end)

The problem is that you detect the input all of the time and hence, you call the function multiple times, and sometimes, before the previous call ended.
This causes functions to run simultaneously.
To prevent this, add a debounce.

local debounce = false -- put this in a global scope so at the top of your script
SkillPossessed.Triggered:Connect(function(plr)
	if debounce == true then return end -- HERE is the change
	debounce = true -- set it to true to prevent any further calls.
	if Use == false then
		Use = true
		UseSkillPossessed(plr,Use)
	elseif Use == true then
		Use = false
		UseSkillPossessed(plr,Use)
	end
	debounce = false -- once the UseSkillPossessed has finished, set debounce to false
	-- thus allowing it to be called again
end)